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

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

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

Cany anyone tell me, why its not working?

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

cboOrganization.DataBindings.Clear()
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 :)

Regards

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.

hello
Use this code , hope this will solve your prob

dim mycon as new sqlconnect("connection string")
mycon.open()
dim da as new sqldataadapter("ur selection query",mycon)
dim dt as datatable 
da.fill(dt)
'take binding source 
bindingsource.datasource = dt
datagride.datasource = bindingsource
'now here you can bind your controls 
txt1.databinding.add("text",bindingsource,"field",false)
combobox.databinding.add("SelectedValue",bindingsource,"field",true)

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

Regards

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 www.dapfor.com

Be a part of the DaniWeb community

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