Home > Net >  DataGridViewComboBoxColumn associated fields display problems
DataGridViewComboBoxColumn associated fields display problems

Time:09-26

How to implement DataGridViewComboBoxColumn in dataGridView binding under the premise of the DataSet, the through DataPropertyName associated data said another way, such as data is 12000 corresponding is high-speed, 7200 is corresponding to the medium speed, the drop-down box shows high speed and low speed, medium speed

Finally run out my code, such as a database inside is 12000, the drop-down box shows 12000, but click on the item is high speed, low speed, medium speed, ask why will this appearance

DataGridViewComboBoxColumn column=new DataGridViewComboBoxColumn ();
The DataTable dt=new DataTable ();
DataColumn dc new DataColumn (" value ", typeof (long));
Dt. Columns. The Add (dc);
Dt. Columns. The Add (new DataColumn (" Name ", typeof (string)));
Dt. Rows. The add (12000, "high speed");
Dt. Rows. The add (7200, "medium");
Dt. Rows. The add (3600, "slow");
The column. The DataSource=dt;//combobox columns of data source, binding for the generated table
The column. DisplayMember="name";//to display the name, table text example
The column. The ValueMember="value";
//this is the database in the corresponding field
The column. DataPropertyName="speed"
  •  Tags:  
  • C#
  • Related