DataGridViewComboBoxColumn, how the bound dataset into the datagridview.
-
-
Hi, I have dataset that is bound to a DataGridView. In my DataSet I have column "name" (string) and column "sex" (int). So far so good. My problem is: Now I need to convert "sex" to a comboBox type with values 0-> male, 1->female. any ideas? tnx
Hi, If you want to do it the hard way, you could choose to set VirtualMode[^] to true. And use a DataGridViewComboBoxColumn[^]. However then you have to manage your datastore manually and all other related functions (including drawing the datagridview). This offers a great deal of flexibility, but is rather complex (though the msdn does give a very nice example). You could also try to replace the column from the datagridview with a DataGridViewComboBoxColumn, but I don't know how to link the dataset to your column then. Greets, basambora
-
Hi, If you want to do it the hard way, you could choose to set VirtualMode[^] to true. And use a DataGridViewComboBoxColumn[^]. However then you have to manage your datastore manually and all other related functions (including drawing the datagridview). This offers a great deal of flexibility, but is rather complex (though the msdn does give a very nice example). You could also try to replace the column from the datagridview with a DataGridViewComboBoxColumn, but I don't know how to link the dataset to your column then. Greets, basambora
I've created a DataGridViewComboBoxColumn named "cbx". Added 0->"male",1->"female" to it's items; I've added the "cbx" to my GridView as "sexA" column and for each row I "sexA".value = "sex".value; i used this line: gridview.Rows[0].Cells["sexA"].value = gridview.Rows[0].Cells["sex"].value; Just as a remainder, "sex" is int type and also the "cbx" value is int type. thought the results should be to show the displaymember on "sexA" by the value of "sex" it doesn't show anything on "sexA". Although later on I can edit and select a new value to "sexA" but can't do that using code! it's seems like it doesn't update the gridview. I tried GridView.Refresh(). Any ideas? tnx