DataGridViewRadioButtonColumn

D

DJE

Using DataGridViewRadioButtonColumn/Cell (http://msdn2.microsoft.com/
en-us/library/aa730882(VS.80).aspx) I want to select in all rows, 1 of
3 radiobuttons in a column of my datagridview programmatically. I am
trying:

string selectedRadioButton=1;
foreach(DataGridViewRow row in Grid.Rows)
{
//get the cell in the 11th column
DataGridViewRadioButtonCell radioButton =
(DataGridViewRadioButtonCell)(row.Cells[11]);

// Update the value of the cell (with a string)
This string should exist as a value of
// your bound datasource's DisplayMember field.
radioButton.Value = selectedRadioButton;

// Update the cell.
Grid.UpdateCellValue(11, row.Index);
}
So I expect this to select the second radio button in each cell. But
radioButton.Value=selectedRadioButton always is null after the
assignment. I have the column bound to an object with 2 fields
(ValueMember=Id and DisplayMember=Description). and the grid in
virtual mode. What do I have to do to set this radio button?
 
D

DJE

I resolved this...sorry for my confusing comments in the code. User
selects 1 of 3 radiobuttons and then the RadioButtonColumn in the grid
mirrors that selection.

Here is the code that worked:

if (radioButton0.Checked)
{
foreach (DataGridViewRow row in Grid.Rows)
{
row.Cells[11].Value = 0;
}
}
 

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