Private Sub DataBinding()
            Dim bsTableName2 As String
            bsTableName2 = "dbo.hrBranchSetup"
            'cboOrganization.DataBindings.Add(New Binding("Text", ds.Tables(bsTableName2), "OsID"))
            brCode.DataBindings.Add(New Binding("Text", ds.Tables(bsTableName2), "BranchCode"))
            cboOrganization.DataBindings.Add(New Binding("SelectedValue", ds.Tables(bsTableName2), "OsID"))
            brName.DataBindings.Add(New Binding("Text", ds.Tables(bsTableName2), "BranchName"))
            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

In my above code, all the data gets bind except with:

cboOrganization.DataBindings.Add(New Binding("SelectedValue", ds.Tables(bsTableName2), "OsID"))

Cany anyone tell me, why its not working?

Recommended Answers

All 5 Replies

Shouldn't you clear the databinding BEFORE you add a new binding?

cboOrganization.DataBindings.Add(New Binding("SelectedValue", ds.Tables(bsTableName2), "OsID"))

hello !
use this code for binding

cboOrganization.DataBindings.Add("SelectedValue", ds.Tables(bsTableName2, "OsID",true)

This will work fine :)


Thanks for your help but i did tried in same manner like yours but the result is same. To make you more understadable, i have attached snapshot of my form, hope it will be clear. This form is taken on FormLoad event, and the solution which i am looking should display on FormLoad only, I get the data bind correctly when i navigate and click on row of datagrid.

Please help me.

Use this code , hope this will solve your prob

dim mycon as new sqlconnect("connection string")
dim da as new sqldataadapter("ur selection query",mycon)
dim dt as datatable 
'take binding source 
bindingsource.datasource = dt
datagride.datasource = bindingsource
'now here you can bind your controls 

If your prob is solved then please mark this thread solved and vote me up :)


I completely understands Ur problem and according to me you'll get your answer in this code

private Control _control;

//The method is called when data is updated (for ex. data comes from TCP/IP)
void OnUpdateReceiced(...)
    _control.Invoke(new MethodInvoker(delegate
        //Raise notification in GUI thread
        OnListChanged(new ListChangedEventArgs(...));


I hope this will helps you.for more information visit on

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.