We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CheckBox DataBinding bug?

Thread ID:

Created:

Updated:

Platform:

Replies:

2040 Dec 11,2002 10:03 AM UTC Sep 25,2003 04:19 AM UTC Windows Forms 2
loading
Tags: FAQ
Istvan Bagyura
Asked On December 11, 2002 10:03 AM UTC

Hi! I have a problem with a bound CheckBox when I want to insert a new row. I bound the cbox to a bit type field ( MS SQL SERVER). It works fine when I want to navigate through the table or I want to modify the values. But when I'd like to insert a new row and I want to navigate to this newly inserted row I can't. It simply don't work. Without the checkbox it works fine. Here is some code: // the databinding // chkAdmin is a CheckBox // dvEmpGroup is a DataView chkAdmin.DataBindings.Add( "Checked" , dvEmpGroup , "isAdmin" ) ; // insert a new row and locate it. // dvEmpGroup is a DataView // newRec is a DataRowView newRec = dvEmpGroup.AddNew() ; BindingContext[ dvEmpGroup ].Position = BindingContext[ dvEmpGroup ].Count ; I guess the problem with the default value of the bound DB field. (What can do a checkbox with a null value?)If I'm right how can I set the default value of a field in a datasource from code? If you know the answers pls write me. Hi! B.I.

Chad Cothern
Replied On March 28, 2003 10:22 PM UTC

I had the same exact problem. I was binding a List box to the same data set as my text boxes so that the list box would control the bindingcontext position. I thought that maybe the problem was the combination of the two controls (one with complex binding and the collection of simple bound text boxes). When I read your message, I realized that I had overlooked my checkbox control. That was definitely it! The database was set to automatically default to 1/True, but you also have to make sure that this is set in your .xsd schema of your dataset (if you use one). In design view of the xsd file, you can select the field and in the Properties window, set default to "true" or "false". It didn't seem to like 1 or 0, or even "True" or "False". It MUST be lowercase to work. After that, my .addnew added the row and automatically pointed to the new record (as it should). If you aren't using a strongly typed dataset (.xsd) then you can set the default by using the following syntax (or something of the equivalent): datasetname.Tables("tablename").Columns("columnname").DefaultValue = "true" Thanks for your post, it helped me solve my problem! > Hi! > > I have a problem with a bound CheckBox when I want to insert a new row. > > I bound the cbox to a bit type field ( MS SQL SERVER). It works fine when I want to navigate through the table or I want to modify the values. > But when I'd like to insert a new row and I want to navigate to this newly inserted row I can't. > It simply don't work. Without the checkbox it works fine. > > Here is some code: > // the databinding > // chkAdmin is a CheckBox > // dvEmpGroup is a DataView > chkAdmin.DataBindings.Add( "Checked" , dvEmpGroup , "isAdmin" ) ; > > > // insert a new row and locate it. > // dvEmpGroup is a DataView > // newRec is a DataRowView > newRec = dvEmpGroup.AddNew() ; > BindingContext[ dvEmpGroup ].Position = BindingContext[ dvEmpGroup ].Count ; > > I guess the problem with the default value of the bound DB field. (What can do a checkbox with a null value?)If I'm right how can I set the default value of a field in a datasource from code? > > If you know the answers pls write me. > > Hi! > > B.I.

Kris_xx
Replied On September 25, 2003 04:19 AM UTC

I also had the same problem and i managed to over come using event handler add the following code segment to initial binding procedure dBindins = New Binding("checked", ds.Tables(0), "RoadTest") AddHandler dBindins.Format, AddressOf FormatHandler CheckBox2.DataBindings.Add(dBindins) then create a cutom procedure call FormatHandler and add the following segment Public Sub FormatHandler(ByVal sender As Object, ByVal e As ConvertEventArgs) If IsDBNull(e.Value) Then e.Value = False End If End Sub when u adding a new record this will check for DBNull and make as Fale Kris_xx

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;