Jun 13th, 2008, 10:04 PM
I have used datagridview in my form show all data and to enter by it.
Now I have a field which is type field which needs only 1 of 7 types. i.e.
2. Type BB
So I want to put combobox in datagrid. How can i asign a combo to my database field in grid.???????
Thank you in advance
Jun 14th, 2008, 02:12 AM
If you right click the grid at design time and select Edit Columns, the Column Editor will appear. Select the column that you want to have appear as a combobox and change the ColumnType property to DataGridViewComboBoxColumn.
Jun 14th, 2008, 07:12 AM
yes u r right, but i want to asign columns at runtime. I dont asign columns invdividually but it takes them from table structure.
After asigning datasource I want to make column(1) a comboboxcolumn.
Jun 14th, 2008, 07:27 AM
You cannot change the type of an existing column at run time. If you don't want to accept the default column type created by the grid then you need to create the column yourself. You can do it in code but you wouldn't. You would do it in the designer as sparrow1 says. You need to set the column's DataPropertyName property to the name of the DataColumn you want it bound to. That way, that column in the DataTable will be bound to your combo box column instead of the grid creating a new one.
By the way, I ignored this thread the first time I saw it because the title said "DataGridComboBoxColumn". If it had said "DataGridViewComboBoxColumn" like it should I would have answered then and you would have got your solution sooner. Names are important. Use the right ones and people will know exactly what you're yalking about.
Jun 15th, 2008, 08:28 PM
ok. So what can I do for it? Can I put validation on this field? If not is there any other control to do so? Can we do it by listview?
If there's not a single positive answer I will have to change concept of my entry form.
Thank you for a cooperation.
Jun 15th, 2008, 08:31 PM
Once you've added the column you can treat it like a ComboBox, so you can add your valid values to its Items collection or you can bind a list to it via its DataSource, just as you would with a regular ComboBox.
Click Here to Expand Forum to Full Width