all groups > dotnet windows forms > october 2006 >
You're in the

dotnet windows forms

group:

Databinding and Dataset


Databinding and Dataset kzoltan
10/12/2006 11:36:02 AM
dotnet windows forms: 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.

Re: Databinding and Dataset Bart Mermuys
10/12/2006 7:14:36 PM
Hi,

[quoted text, click to view]

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]

Re: Databinding and Dataset kzoltan
10/16/2006 7:07:02 PM
Thank you for the response.
Unfortunately, the GetListName returns "IBindingList" instead of the table
name. If I do bs.List I get an invalid cast, since bs.List is an
IBindingList.


[quoted text, click to view]
AddThis Social Bookmark Button