DataGridView displaying different levels of data

Source: Internet
Author: User

as we all know, DataGridView you can directly bind the data source to display the data in the database. But what I want to do is to make a conditional query on him and select different levels of records based on the user level.

the above control is DataGridView control that can be used to directly bind a data source to display data from a table in a database.

after adding the control, come out a DataGridView task, the data source is bound successfully as per step step.

A table is created after the data source is bound,


The next step is to add the query, note that the query statement should not be written incorrectly.

Note that our query statements cannot be written incorrectly. The query user level for the general user is written as:

SELECT *from Table Where level= " General Users " , then click Query Builder. And so on, each query out 3 User-level corresponding information.



when we click on different user level information will come out corresponding to the user information. But this is not the effect I want, I want to use a Combobox control, will make their interface beautiful. Of course, the top of the general user, administrator, operator. that is, the ToolStrip control can be converted to a Combobox control. But how to use after conversion, I do not, so I think of a stupid method.

Add a Combobox control, on the interface TOOLSTRIPC Delete, although deleted, but the code to add the query is still there. I made some changes to the code and changed it to the combobox_selectedindexchanged event. then change the UserID,UserNameandHead into Chinese form. Edit column (HeaderText property)

Private Sub combobox1_selectedindexchanged_1 (sender as Object, e as EventArgs) Handles combolevel.selectedindexchanged< C0/>if Combolevel.text = "General user"    then "if Combolevel is the average user, then the record me.t_userinfotableadapter for the average user is queried            . General User ( Me.UserInfo.T_UserInfo)        End if if        combolevel.text = "operator"    then "if Combolevel chooses operator, the operator's record is queried            Me.t_ Userinfotableadapter. Operator (Me.UserInfo.T_UserInfo)        End if        if Combolevel.text = "admin" then     " If Combolevel chooses an administrator, query the administrator's record            me.t_userinfotableadapter. Administrator (Me.UserInfo.T_UserInfo)        End If    end Sub

Run

To add a query without code, turn a small bend. I do not use this method of code, almost all the way the control is bound, just modify a little bit of code.

     Anyway, the method may be a bit stupid, but it feels relatively simple, Everyone has a better way to tell me oh. Thank you. DataGridView controls are really handy, but learn to use code to implement a variety of functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.