GuidoG
GuidoG

Reputation: 12014

Get the bindingsource from a control

I need a way to find the bindingsource that a control is bound to. For example, when textbox1 is bound to bindingsource1 than I need a function with input textbox1 and it should return bindingsource1

example

textBox1..DataBindings.Add("Text", bindingSource1, "name", true);

private BindingSource GetBS(Control something)
{
    return the bindingsource from Control
}

so when calling GetBS(textBox1) it should return bindingSource1

Anyone has some idea how to do this ?

Upvotes: 1

Views: 586

Answers (1)

Luc Morin
Luc Morin

Reputation: 5380

Actually, the BindingSource will not be found on the TextBox itself, but on a specific Binding, for example the "Text" Binding.

You should be able to do something like this:

        var source = textBox1.DataBindings["Text"].DataSource;

Hope this helps

Upvotes: 2

Related Questions