Hi,
[quoted text, click to view] "kzoltan" <kzoltan@discussions.microsoft.com> wrote in message
news:DCBAB43C-BF75-4A29-BFBE-974580484DF5@microsoft.com...
> Hi,
>
> I am trying to determine the name of the datatable that a control is bound
> to using code. For example: I have a textbox which is bound to a
> bindingsource. The bindingsource is either bound to a dataset's datatable
> or
> another bindingsource and a relation (typical master detail setup). How
> can
> I determine the name of the underlying datatable that the control is bound
> to?
>
> Scenario 1: textbox, bound to bindingsource, bindingsource datasource is
> a
> dataset, datamember is a datatable.
> Scenario 2: textbox is bound to a bindingsource, bindingsource is bound
> to
> another bindingsource - datasource is binding source, datamember is a
> relation such as master_detail.
You can get the BindingSource from a Control property binding like this:
BindingSource bs = (BindingSource)
someTextBox.DataBindings["Text"].DataSource;
Once you have the BindingSource you can get the name of the underlying
DataTable:
Console.WriteLine( bs.GetListName(null) );
-or-
Console.WriteLine( ((DataView)bs.List).Table.TableName );
HTH,
Greetings
[quoted text, click to view] >
> Thank you very much for your help.