PC Review


Reply
Thread Tools Rate Thread

DatagridView - Disable a combobox-cell in specific rows

 
 
Klaus Jensen
Guest
Posts: n/a
 
      15th Nov 2006
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?


 
Reply With Quote
 
 
 
 
kferron
Guest
Posts: n/a
 
      15th Nov 2006

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





On Nov 15, 7:56 am, "Klaus Jensen" <spamm...@burninhell.com> wrote:
> 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?


 
Reply With Quote
 
Klaus Jensen
Guest
Posts: n/a
 
      15th Nov 2006
"kferron" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

Thank you for your answer.

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


I'm not sure either!

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable DataGridView Combobox cell Bofors Microsoft Dot NET Framework Forms 0 18th Jul 2008 04:50 AM
DatagridView Disable some rows selection =?Utf-8?B?RGlvZ28gQWx2ZXMgLSBTb2Z0d2FyZSBEZXZlbG9w Microsoft C# .NET 2 26th Feb 2007 02:11 PM
DataGridView - BindingSource (Object) and ComboBox cell Przemek M. Zawada Microsoft C# .NET 3 24th Feb 2007 01:05 PM
DataGridView ComboBox Cell Trouble. Karen Hill Microsoft C# .NET 0 13th Aug 2006 01:19 AM
Old value of a datagridview combobox cell Bob Microsoft VB .NET 2 10th Jan 2006 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:47 AM.