The ComboBox column bound data source is added to the datagridview in winform.

Source: Internet
Author: User

I have very little access to winform and recently Want To Do This function:

Add a column (out of the data source) to the datagridview)

Solution:

1. manually add a column to the datagridview (right-click the datagridview)

2. The datagridview is bound to the datatable data source. In this case, my data in ComboBox is

3. loop through each row of the datagridview and bind data to ComboBox (dropdownlist.

PS: It's just a personal method. I think this method is not very efficient. After all, it is bound with two data records. Please give me some tips if you have any good methods.

For (INT I = 0; I <datagridview1.rows. Count-1; I ++)

{

VaR dropdownlist = (datagridviewcomboboxcell) datagridview1.rows [I]. cells ["column2"]; // obtain the control ComboBox

admintableadapter ata = new admintableadapter (); // instantiate the adapter
datatable dt = ATA. getdata (); // obtain the data source
dropdownlist. datasource = DT; // bind the data source
dropdownlist. displaymember = "username";
dropdownlist. valuemember = "ID";
}

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.