|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
databindingdatabound control to an integer field on a database. I am using Format and Parse with the checkbox to write -1 to the database if the checkbox is unchecked and 0 if checked. I am finding that the Dataset and Database are not updated if I change the checkstate of the checkbox and when I change the checkstate of the textbox, the other controls (textboxes) will not allow focus. The code I have written is below. Any suggestions would be appreciated. // chbActive System.Windows.Forms.Binding chkBoxBinding = new System.Windows.Forms.Binding("CheckState", this.tblEmployeeBindingSource, "inActive", true); chkBoxBinding.Format += new System.Windows.Forms.ConvertEventHandler(IntegerToCheckState); chkBoxBinding.Parse += new System.Windows.Forms.ConvertEventHandler(CheckStateToInteger); this.chbActive.DataBindings.Add(chkBoxBinding); this.chbActive.CheckStateChanged += new System.EventHandler(this.chbActive_CheckStateChanged); //this handles integer to checkstate private void IntegerToCheckState(object sender, ConvertEventArgs cevent) { // the method converts only to CheckState inActive is 0 if false if ((int)cevent.Value == 0) { chbActive.CheckState = CheckState.Checked; } else { chbActive.CheckState = CheckState.Unchecked; } } private void CheckStateToInteger(object sender, ConvertEventArgs cevent) { // if Active is checked then they are active and inActive should be 0 if (chbActive.CheckState == CheckState.Checked) { cevent.Value = 0; } else { cevent.Value = -1; } } Hi,
I did not completely evaluate your code, however, do you know that if you change the checkstate, you are throwing the event that it is changed. In my idea is that almost endless in your code. A solution?. Remove the handling of the event direct after that you use it and set it again if you have changed the values. Cor |
|||||||||||||||||||||||