Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid View Cell Click problems 1

Status
Not open for further replies.

dseaver

IS-IT--Management
Jul 13, 2006
467
I have a Check Box Column that i want to have only one itme checked anytime. The function I wrote works, but it doesn't take affect immediately, I have to click away from the cell before the check mark changes. Is there away for the value to change immediately? Here is my eventhandler

Code:
void AllowOneCheckInColumn(object sender, DataGridViewCellEventArgs e)
        {
            if (Convert.ToBoolean(datagrid[e.ColumnIndex, e.RowIndex].Value))
            {
                foreach (DataGridViewRow row in datagrid.Rows)
                {
                    if (row.Index != e.RowIndex)
                    {
                        row.Cells[datagrid.Columns[e.ColumnIndex].Name].Value = false;
                    }
                }
            }
        }
The event is DataGridView.CellValueChanged
 
Awesome. I guess i should have RTM. I had to change my function slightly, since this eventhandler happens BEFORE the value is changed, here is what I used, incase someone else wants to do the same.

Code:
void AllowOneCheckInColumn(object sender, DataGridViewCellEventArgs e)
        {
            if ([b]![/b]Convert.ToBoolean(datagrid[e.ColumnIndex, e.RowIndex].Value))
            {
                foreach (DataGridViewRow row in datagrid.Rows)
                {
                    if (row.Index != e.RowIndex)
                    {
                        row.Cells[datagrid.Columns[e.ColumnIndex].Name].Value = false;
                    }
                }
            }
        }
 
I only had it handy because I was looking through the other day for my own fun GUI issue (ComboBox selected *value* is changed before SelectionChangeCommitted event, but *text* is not changed until after).

Hope it made your day a little more fun than mine was ;-)

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top