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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagridview checkbox column question

Status
Not open for further replies.

moongirl129

Programmer
Sep 5, 2002
38
GB
I have a datagridview which is databound to an object. There are 4 properties in this object all boolean which are shown as checkboxes in the datagridview.

I want them to act like radiobuttons so when one is checked the others are all unchecked. So I added a method to my class so that whenever one of these properties is set to true the others are all set to false. This works but ...... the set of each property only seems to fire when focus is lost, not when the property is actually changed.

I've come across this before with a standard checkbox and I know to fix the problem you change the databinding to include DataSourceUpdateMode.OnPropertyChanged. I can't find a similar way of changing this property for the datagridview column. Can anyone help??
 
you could convert the checkbox column to a template column.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I didn't think you could use templateColumns with a datagridview (Windows Forms)? I thought you could only use them in a datagrid in asp.net. If I'm wrong could you point me to an example? Thanks.
 
i'm sorry. I was thinking web, not windows. could you iterate through the checkbox column examing child controls? something like this:
Code:
public function AssignCheckBoxHandler(Control control)
{
   if (control == null)
   {
       return;
   }
   else if (control is CheckBox)
   {
      ((CheckBox)c).CheckedChanged += new EventHandler(MyCheckBoxEvent);
   }
   else
   {
      foreach(Control c in control.Controls)
      {
         AssignCheckBoxHandler(c);

      }
   }
}

private void MyCheckBoxEvent(object sender, EventArgs e)
{
   CheckBox checkBox = (CheckBox)sender;
   ...
}
I haven' designed desktop apps before so I may be way off.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top