>Hello all, I have a form whose textboxes can be bound to either of two DataSets, is there a way to determine which DataSet they're bound to at runtime ?
>
>// pseudo code
>
>
>if(this.txtAddr1.DataBinding is MyDataSet1)
> someaction;
>else
> someotheraction;
>
>
Pete,
if (this.txtAddr1.DataBindings["Text"].DataSource is MyDataSet1)
Would work but it'd only look for if they're of same type (class). If you have multiple instances of MyDataSet1 (with desingner generated datasets unlikely) which might have different datasets then you'd only be checking like ( if myTextBox's class is same as MyDataSet1 class ).
Aaargh, I can't even understand it when I write in plain English:)
Consider this:
DataSet ds1 = new DataSet("Northwind");
DataSet ds2 = new DataSet("Pubs");
// populated their tables
Binding 2 textboxes to some field from each one of those:
if (this.txt1.DataBindings["Text"].DataSource is DataSet)
if (this.txt2.DataBindings["Text"].DataSource is DataSet)
both return true. They both directly are derived from DataSet. What I want to know is if txt1 uses DataSet 'ds1', right? So:
if (this.txtAddr1.DataBindings["Text"].DataSource.Equals(this.dsName))
dsName refers to instance name on form. Likely in your case it's 'myDataSet1'.
The difference is that this makes an 'object' comparison between DataSource and 'YourDataSet'.
PS: You wouldn't believe I actually wrote this about 2 hrs ago. Internet was disconnected:( Hope now send succeeds.
Cetin