DatagridView - Disable a combobox-cell in specific rows

K

Klaus Jensen

I have been battling with this problem for hours, and I am now completely
stuck.

The problem (simplified):

I have a databound datagridview, which has 3 columns: Name (text-column),
VerifiedDriversLicense (checkboxcolumn) and CarAssigned (databound
combobox-column)

If VerifiedDriversLicense checkbox is checked for a row, a value from the
databound CarAssigned Combobox can be chosen. If VerifiedDriversLicense is
NOT selected, I need to be able to make CarAssigned combobox invisible,
readonly, a different color or something like that.

This should be pretty straightforward, and I tried this approach:

First I run a sub to bind data

Then I run a sub to process the datagrid to apply the above mentioned logic:


Dim veriFiedDataGridViewCheckBoxCell As DataGridViewCheckBoxCell
Dim carAssignedDataGridViewComboBoxCell As DataGridViewComboBoxCell

For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells("colVerifiedDriversLicense").Value = 0 Then
carAssignedDataGridViewComboBoxCell =
CType(row.Cells("colCarAssignedDataGridViewComboBoxCell"),
DataGridViewComboBoxCell)
carAssignedDataGridViewComboBoxCell.Readonly = True
carAssignedDataGridViewComboBoxCell.Style.BackColor = Color.Black
End If
Next

(it's pseudocode, it might contain typos)

....But it does now work! I tried stepping through the code, and the
code-lines carAssignedDataGridViewComboBoxCell.Readonly = true are run, but
nothing happens. The combobox is NOT readonly

What am I missing? Is it not possible to make a combobox in a single cell
readonly?
 
K

kferron

I'm not sure you're understanding the order of processing here.

If you were to set up a break point in the foreach loop, you would
realize that your sub process is occuring at the wrong time in page
execution.

What you are trying to do can be accomplished by providing an
EventHandler for GridView.ItemDataBound.


~kcf
 
K

Klaus Jensen

Thank you for your answer.
I'm not sure you're understanding the order of processing here.

I'm not sure either! :D
What you are trying to do can be accomplished by providing an
EventHandler for GridView.ItemDataBound.

I looked for that event earlier, but there is no such event, which I know
from good old datagrid.

However, that lead me to the DatabindingComplete event, where I can do I
what I am looking for

Thanks :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top