C # How to Use the DataGridViewComboBoxColumn of the DataGridView in Winform

Source: Internet
Author: User

The following describes how to use the DataGridViewComboBoxColumn of the DataGridView in Winform:

 

DataGridViewComboBoxColumnManually bind data sources

 

1 // by default, AllowUserToAddRows is set to False. Therefore, create a DataGridViewRow and add it to the DataGridView.
2 DataGridViewRow dgvr = new DataGridViewRow ();
3 dgvDownloadList. Rows. Add (dgvr );
4
5 // obtain the data source
6 List <ServiceInterface. dmsManageWCFService. dmsDocumentInfo> DIList = PDMService. DmsManageWcfServiceJoint. GetAllHistroyVersion (item. DocGUID );
7
8 DataTable dtVersion = new DataTable ();
9 DataColumn dcVersion = new DataColumn ("Version"); // display Name
10 DataColumn dcVerGUID = new DataColumn ("VerGUID"); // bound Value
11 dtVersion. Columns. Add (dcVersion );
12 dtVersion. Columns. Add (dcVerGUID );
13
14 foreach (ServiceInterface. dmsManageWCFService. dmsDocumentInfo cVerDoc in DIList)
15 {
16 dtVersion. Rows. Add (cVerDoc. DocVer, cVerDoc. VerGUID );
17}
18
19 (DataGridViewComboBoxCell) dgvDownloadList. Rows [0]. Cells ["Version"]). DataSource = dtVersion;
20 (DataGridViewComboBoxCell) dgvDownloadList. Rows [0]. Cells ["Version"]). ValueMember = "VerGUID ";
21 (DataGridViewComboBoxCell) dgvDownloadList. Rows [0]. Cells ["Version"]). DisplayMember = "Version ";
22
23 // bind the initial Value to display the Name, and bind the Value
24 (DataGridViewComboBoxCell) dgvDownloadList. Rows [0]. Cells ["Version"]). Value = item. DocVerGuid;
25
26 // bind the default null value
27 (DataGridViewComboBoxColumn) dgvDownloadList. Columns ["Version"]). DefaultCellStyle. NullValue = "-- select --";

 

Related Article

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.