Check/UnCheck in DataGridView

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi..I have a question related to datagridview.The datagridview is bound to database.
In db i have a table name as TblTerminal which consists of 4 columns i.e.TerminalId int,TermnlNum smallint,Active bit and Retired bit.As the dgv is bound to database,Active and Retired columns in datagridview are appearing as checkbox.Now i want to check
any one of the Active or Retired field within gridview.
Example: The user has to click either on Active or Retired.Now if the user has checked Active field he should not be able to check the Retired field vice versa.And if at all the user wants to check the other field he should be displayed
with a message "To uncheck the first field and check the second vice versa".I have written the code in this manner:

private void dgvTermnl_CellContentClick(object sender, DataGridViewCellEventArgs e)<br/>
{<br/>
<br/>
<br/>
for (int i = 0; i < dgvTermnl.Rows.Count - 1; i++)<br/>
{<br/>
for (int i = 0; i < dgvTermnl.Rows.Count - 1; i++)<br/>
{<br/>
if (dgvTermnl.Rows.Cells[2].Selected == true)<br/>
{<br/>
dgvTermnl.Rows.Cells[3].ReadOnly = true;<br/>
//MessageBox.Show("UnCheck the first cell and then Check the second Cell");<br/>
}<br/>
else<br/>
{
<br/>

<br/>
}<br/>
}<br/>
}<br/>
MessageBox.Show("First UnCheck the Active cell and then Check the Retired Cell");<br/>
<br/>
}<br/>
I am unable to get beyond this.Can anyone say me what extra line do i have to mention.
Hope u understood my doubt.
<
Thanks & Regards Nazima Mahmood<br/>

View the full article
 
Back
Top