DataGridView display data according to the drop-down list
As we all know, the DataGridView can be directly bound to a data source to display data in the database. However, what I want to do is to query him by condition and select different levels of records based on the user level.
The preceding control is the DataGridView control, which can be used to directly bind data sources to display table data in the database.
After the control is added, a DataGridView task is created. The data source is successfully bound as per the steps.
After the data source is bound, the expected table is displayed, <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140726/20140726091518259.png" alt = "\">
2. Add a query. Do not write an error in the query statement.
Note that the query statement cannot be written incorrectly. If the query user level is normal, the following statements are written:
SELECT * FROM table Where Level = "normal user"And then click query generator. Similarly, three user-level information is queried.
When we click on different user-level information, the corresponding user information is displayed. But this is not what I want. I want to use the Combobox control, which will make my interface look better. Of course, the above average user, administrator, and operator. That is, the ToolStrip control can be converted to the Combobox control. But I don't know how to use it after conversion, So I thought of a stupid method.
I added a Combobox control and deleted ToolStripc on the interface. Although I deleted it, I still had some code to add the query. Modify the code to the Combobox_SelectedIndexChanged event.
Change UserID, UserName, and Head to Chinese. Edit a column (HeaderText attribute)
Private Sub comboboxtransferselectedindexchanged_1 (sender As Object, e As EventArgs) Handles comboLevel. selectedIndexChanged If comboLevel. text = "general user" then' if the ComboLevel selects a general user, query the general user's record Me. t_UserInfoTableAdapter. average user (Me. userInfo. t_UserInfo) End If comboLevel. text = "operator" then' if ComboLevel selects operator, query operator's record Me. t_UserInfoTableAdapter. operator (Me. userInfo. t_UserInfo) End If comboLevel. text = "Administrator" then' if ComboLevel selects an administrator, query the Administrator's record Me. t_UserInfoTableAdapter. administrator (Me. userInfo. t_UserInfo) End If
Run
This method seems a bit stupid, but I only used the method of binding controls and directly querying controls, and almost did not write any code. The functions of the DataGridView control itself are very powerful and do not need to write code, bind the project data source directly and add the query directly. But you must also learn code query .... Hey.
Do you have any good methods to teach me and consult carefully. Learning ......