Question Databinding Problem...

tashiduks

Member
Joined
Apr 19, 2010
Messages
22
Programming Experience
Beginner
HI Everyone,

VB.NET:
Private Sub DataBinding()
        Try
            Dim bsTableName2 As String
            bsTableName2 = "dbo.hrBranchSetup"
            brCode.DataBindings.Clear()
            brCode.DataBindings.Add(New Binding("Text", ds.Tables(bsTableName2), "BranchCode"))
            brName.DataBindings.Clear()
            cboOrganization.DataBindings.Add(New Binding("SelectedValue", ds.Tables(bsTableName2), "OsID"))
            cboOrganization.DataBindings.Clear()
            brName.DataBindings.Add(New Binding("Text", ds.Tables(bsTableName2), "BranchName"))
            bsOnlineYNCheckBox.DataBindings.Clear()
            bsOnlineYNCheckBox.DataBindings.Add(New Binding("Checked", ds.Tables(bsTableName2), "OnLineBrYN"))
        Catch ex As Exception
            MessageBox.Show("Error No : " & Err.Number & vbCrLf _
                            & "Error : " & ex.Message & vbCrLf _
                            & "Source : " & Err.Source & vbCrLf _
                            , "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

I can bind other value except with combo box line:
VB.NET:
cboOrganization.DataBindings.Add(New Binding("SelectedValue", ds.Tables(bsTableName2), "OsID"))
cboOrganization.DataBindings.Clear()

Please help me, where i do the wrong?
 
The code you have will do something with the value selected by the user, but it won't add any items to select. Are you setting the DataSource, DisplayMember and ValueMember?
 
You should have already, but now would be a good time to explain what not being able to bind actually means. Is an exception thrown? If so, what is the error message. If not, what actually does happen?
 
well, there is not error message, when i load form,

For Example:

In Mytable, first row contains this value : 0001, 0003, Head Office...and so on

In the form, all the value is loaded in respective controls except for combo box as per my binding code. in place of value 0003 its been loaded different value. There is no such error message.

I am facing problem in this line.
VB.NET:
cboOrganization.DataBindings.Add(New Binding("SelectedValue", ds.Tables(bsTableName2), "OsID"))
cboOrganization.DataBindings.Clear()

Sorry for my bad english, i hope you have got what i am trying to say.
 
I am facing problem in this line.
VB.NET:
cboOrganization.DataBindings.Add(New Binding("SelectedValue", ds.Tables(bsTableName2), "OsID"))
cboOrganization.DataBindings.Clear()
That is not a line, that is two lines.
Do you know what DataBindings.Clear() means? The method is documented at MSDN (which has lots of other languages also): ControlBindingsCollection.Clear Method (System.Windows.Forms)
 
You should change the way youu do data access.. Read the DW4 link in my signature, section "Creating a Simple Data App"

And.. add your combos with drag n drop from the DataSources window.. ;)
 
Back
Top