How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Hi,
My application is in VS2008 and coded in VB.net.
I have a datagridView(DGV) on one of my form.DGV contains a column of type DatagridViewComboboxColumn.I have another column of SrNo.
Consider Table1 to be the table from where my DatagridView is filled which contains following fields SrNo,Value1,Value2.
My requirement is i want to fill the values in my DatagridViewComboboxColumn from Table1.The DatagridViewComboboxColumn's combobox should contain values of columns Value1,Value2 of Table1.
Sample data of Table1
SrNo Value1 Value2
1 2 3
2 4 5
As data in datagridView is filled from Table1 the data of SrNo column of Table1 is also populated in one of the column of DGV.
Now my DatagridViewComboboxColumn combobox should contain the values of Value1 and Value2 of Respective SrNo.
Like Row one of my DGV has SrNo 1 as first value,so the Value1 and Value2 of SrNo 1 should be added to the row's DatagridViewComboboxColumn.
Select distinct Value1,Value2 From Table1 where SrNo=DGV.items(0,DGV.currentcell.rowIndex).value.Hope this Query willl make things more clear
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Sir im aware of how to fill the datagridview...
i want to fill the DatagridViewComboboxColumn.Please help how can i fill that combobox in DatagridView.DatagridViewComboboxColumn should have the values of columns Value1 and Value2 from Table1.
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
Just read this i think this will give clearer idea.
Please check.
I have a datagridview with three columns which is filled using Datareader. There is a DatagridViewComboboxcolumn in the datagridView.
I want this DatagridViewComboboxcolumn should also be filled using datareader.
Please suggest how can i add items to DatagridViewComboboxcolumn using Datareader. Below is the code that i have tried.
Here dr is SqlDatareader
I want to assign the value of Column3 to my DatagridViewComboboxcolumn
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
I'm going to jump in (only to be ridiculed later). I believe you want to populate the ComboBox column's drop down items using Value1 & Value2. Essentially you have a two column DGV: first column has SrNo, second column has no value, yet, but the drop down items are Value1 & Value2 from that record (???). If I'm wrong stop reading now.
You can set the DropDown Items programatically, however, they will be the same for each row in the DGV (which doesn't fit your requirements). The only way I believe would be to:
1. catch the event each time the selection changes in the DGV
2. get the SrNo for that row in the DGV
3. get the Value1 & Value2 from your table which correspond to the SrNo
4. clear then add these values to the ComboBoxColumn's Items
5. may need some sort of DGV refresh/invalidate/etc. to redraw the dropdown items
This will set the Items for the entire DGVColumn, however, they should change every time you change rows.
Re: How to add Items in the DatagridViewComboboxColumn of DatagridView during runtime
He did say he wanted the value from column 3 so I think that means he only wants the one, though it is hard to tell when they do not give direct answers to questions
Bookmarks