I have a DataGridView with three columns. The first two columns contain
ComboBoxes, the third column contains textboxes. The ComboBoxes of the
first column always have the same list of items, but in the second
column, the items depend on the selection of the cell in the first
column (so for each row there can be different items in the ComboBox of
the second column).
How can I realize this? How can the data source for the
DataGridViewComboBoxColumn control what items to deliver (i.e. how can
the data source know which row is the one that will be provided with
data)?
Regards, Jens
jens.ro - 08 Apr 2006 10:55 GMT
I thought about the following solution:
I create an event handler for the CellEnter event. When the event
occurs for a cell of the second column, I check the value of the cell
in the first column and set the data source for the second column
accordingly.
Any comments to this solution? Is there a better one?
Jens
jens.ro - 08 Apr 2006 14:40 GMT
I've found a better solution on my own:
I found out that each cell in the column can have its own data source.
So what I'm now doing is reacting on the CellValueChanged event for the
first column. Inside the event handler I check the value of the cell in
the first column and set the data source of the cell in the second
column accordingly. Additionally I reset the value of the cell in the
second column to a default value to fit to the new data source.
This works fine except one problem I have:
The cell in the second column is only updated when I move the focus to
another cell. What can I do to have the cell updated immediately?
Jens
Fran Garcia - 19 May 2006 10:40 GMT
Jens,
I have exactly the same problem. Moreover, I don't want to fill the combo
box until it is going to drop down. I don't want to access database many
times just to fill combo boxes that might never be opened (or whose data
might change before they are dropped down).
Did you come up with a solution?
Thanks in advance,
Francisco Garcia
>I have a DataGridView with three columns. The first two columns contain
> ComboBoxes, the third column contains textboxes. The ComboBoxes of the
[quoted text clipped - 9 lines]
>
> Regards, Jens
jens.ro - 24 May 2006 19:18 GMT
Unfortunately, my above solution is not perfect. When the user adds a
new row, I get a cell error event. Up to now I don't have a solution
for that. Also the problem with the not updating cell content is not
yet solved. I will post as soon as I have a solution.