Checkboxes for checked and unchecked
Hi,
In windows application i taken datagridview displaying rows with checkboxes
user has to checked only one at a time.
i can take radiobutton but client is asking only with checkboxes......
so i need code for this can anybody help for this situation
Thanks And Regards,
Vijay..........
Re: Checkboxes for checked and unchecked
I remember doing something like this. I had two checkboxes, but only one was allowed to be checked at a time. I just wrote some basic event handling that was executed each time one of the boxes was checked.
I don't remember the exact syntax, but I think it went something like this
Code:
CheckBox1_checked()
{
CheckBox2.enabled = false;
}
CheckBox2_checked()
{
CheckBox1.enabled = false;
}
That way, each time one of the boxes is checked, the other will be unchecked. You can also set, as a default, for one of them to be checked.
Re: Checkboxes for checked and unchecked
Quote:
Originally Posted by asantavicca
I remember doing something like this. I had two checkboxes, but only one was allowed to be checked at a time. I just wrote some basic event handling that was executed each time one of the boxes was checked.
I don't remember the exact syntax, but I think it went something like this
Code:
CheckBox1_checked()
{
CheckBox2.enabled = false;
}
CheckBox2_checked()
{
CheckBox1.enabled = false;
}
That way, each time one of the boxes is checked, the other will be unchecked. You can also set, as a default, for one of them to be checked.
Good answer... but doesn't this code need to read:
Code:
CheckBox1_checked()
{
CheckBox2.checked= false;
}
CheckBox2_checked()
{
CheckBox1.checked = false;
}
By setting the "enabled" property to false, you are making it such that the field cannot be checked/unchecked at all!
Re: Checkboxes for checked and unchecked
Quote:
Originally Posted by masaboina
Hi,
In windows application i taken datagridview displaying rows with checkboxes
user has to checked only one at a time.
i can take radiobutton but client is asking only with checkboxes......
so i need code for this can anybody help for this situation
Thanks And Regards,
Vijay..........
You may try to explain to your client that using a radio button implies exclusivity whereas checkboxes do not. Using the proper control for the situation makes for better usability for the end users - it would be kind of like using a listbox as a button.
Re: Checkboxes for checked and unchecked
Quote:
Originally Posted by ronmoles
Good answer... but doesn't this code need to read:
Code:
CheckBox1_checked()
{
CheckBox2.checked= false;
}
CheckBox2_checked()
{
CheckBox1.checked = false;
}
By setting the "enabled" property to false, you are making it such that the field cannot be checked/unchecked at all!
Yes. I was just trying to get the idea across.
And, as Arjay said, it would be wise to advise your client on the benefits of sticking to standards.
Re: Checkboxes for checked and unchecked
This talk of standards and RadioButtons is all well and good but this is within a DataGridView, not just on a form. There is no radio button column by default so unless you want to create your own you're stuck using the check box column. Creating your own wouldn't be too hard but the check box column is fine for this.
Code:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == checkBoxColumnIndex && (bool)this.dataGridView1[e.ColumnIndex, e.RowIndex].Value == true)
{
for (int rowIndex = 0; rowIndex < this.dataGridView1.Rows.Count - 1; rowIndex++)
{
if (rowIndex != e.RowIndex)
{
this.dataGridView1[e.ColumnIndex, rowIndex].Value = false;
}
}
}
}