VB.NET : How Can i Bind data to CheckBox
-
I just start to work with VB.NET and i designed a form that allows me editing customer records. The code is as follows : Private Sub BindingFields() con = MyConnection.GetHandler() Mydataset = New DataSet() MyAdapter = New SqlClient.SqlDataAdapter("select * from client", con) MyBuilder = New SqlClient.SqlCommandBuilder(MyAdapter) MyAdapter.Fill(Mydataset, "client") TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_codcli")) TextBox2.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_adrcli")) TextBox3.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_tel1")) TextBox4.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_nomcli")) TextBox5.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_tel2")) TextBox6.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_fax")) TextBox7.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_datcre")) TextBox10.DataBindings.Add(New System.Windows.Forms.Binding("Text", Mydataset, "client.r01_remcli")) CheckBox1.DataBindings.Add(New System.Windows.Forms.Binding("checked", Mydataset, "client.stop_serv")) 'da.Fill(Mydataset, "Categorie") 'ComboBox1.DataSource = Mydataset 'ComboBox1.DisplayMember = "categorie.libelle" End Sub and the code of the AddNew button is as follows : Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click AddRecord() End Sub 'This routine add a blank record Private Sub AddRecord() Mode = "A" Try Me.BindingContext(Mydataset, "client").EndCurrentEdit() Me.BindingContext(Mydataset, "client").AddNew() TextBox1.Text = Getautocode() TextBox4.Focus() Catch eEndEdit As System.Exception System.Windows.Forms.MessageBox.Show(eEndEdit.Message) End Try End Sub Someone can tell me for why the fields don't become empty when i click on the addnew button . whereas, when i disabled the line : CheckBox1.DataBindings.Add(New System.Windows.Forms.Binding("checked", Mydataset, "client.stop_serv")) the code works correctly. Thank you very much. ***