Changingbound DataView Table property fat runtime

  • Thread starter Thread starter Andy Gilman
  • Start date Start date
A

Andy Gilman

The designer does a great job of letting you map fields to a DataView but I
dont want to have to use the dataset it creates at runtime because I want to
be able to use my own dataset from my dataaccess layer. I want my display
components to be loosely coupled and more flexibly reusable

The designer generated code creates me 'dataView1' and binds all my controls
to it. What I wanted to do was bind the DataView to a new table at runtime
by using :

dataView1.Table = DataAccess.LoadCustomers();

This works, but only the first time. If I try and set it again it wont work
and all text fields are blanked out!

The MS help says "You can only set the Table property if the current value
is null."

So this implies I can only set it once. However the designer in its code has
already set it

//
// dataView1
//
this.dataView1.ApplyDefaultSort = true;
this.dataView1.Sort = "Customer_key";
this.dataView1.Table = this.tseDataSetTMDB1.customers;

So I must be able to set the Table property at least twice since the
designer has done it. Therefore what does this "You can only set the Table
property if the current value is null." comment mean?

How can I reset the table used by a DataView at runtime and have all its
bound controls work? Since the DataView is handling the proxying to the
table then surely this should be possible.

-simon
 
Why don't we give it a try to

dataview1.table = null;
dataView1.Table = DataAccess.LoadCustomers();

first detach any table binded with the dataview and attach the table you
want.

Regards,
Rajesh Patel
 
i'm pretty sure i already tried that
but it didnt work.

whats stranger is i have a problem even binding to a combobox's Text
property unless I manually setup the bindings in my code.ive seen some
miscellaneous bugs with comboboxes and databinding (liek the fact that it
gets confused if you try and access SelectedValue before the combobox has
been displayed).

i think i'll jsut stick with doing it manually. its too much of a headache
using the designer.

-simon
 
Hi Andy,

I think that bindings go invalid since they are not bound to the same source
anymore.
You might remove them and add them again.
Another workaround would be to copy the data into orignal table (instead of
assigning new table to dataview).
 
this is exactly why I used a DataView because i figured that I could 'trick'
the bindings into thinking they were bound to the same thing. and this is
true the dataview reference doesnt change.

the wierd thing was that if i accessed the currency manager and looked at
the 'Current' object then this DID correctly reflect the new table.

this is very odd!

are most people just binding directly to a single form for all their data?
there have to be articles on more advanced databinding like this with user
controls. modern user interfaces allow users to change things from lots of
different places and it looks to me like .net binding just doesnt support
things like this very well. or am i missing something?

-simon


Miha Markic said:
Hi Andy,

I think that bindings go invalid since they are not bound to the same source
anymore.
You might remove them and add them again.
Another workaround would be to copy the data into orignal table (instead of
assigning new table to dataview).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Andy Gilman said:
The designer does a great job of letting you map fields to a DataView
but
I
dont want to have to use the dataset it creates at runtime because I
want
to
be able to use my own dataset from my dataaccess layer. I want my display
components to be loosely coupled and more flexibly reusable

The designer generated code creates me 'dataView1' and binds all my controls
to it. What I wanted to do was bind the DataView to a new table at runtime
by using :

dataView1.Table = DataAccess.LoadCustomers();

This works, but only the first time. If I try and set it again it wont work
and all text fields are blanked out!

The MS help says "You can only set the Table property if the current value
is null."

So this implies I can only set it once. However the designer in its code has
already set it

//
// dataView1
//
this.dataView1.ApplyDefaultSort = true;
this.dataView1.Sort = "Customer_key";
this.dataView1.Table = this.tseDataSetTMDB1.customers;

So I must be able to set the Table property at least twice since the
designer has done it. Therefore what does this "You can only set the Table
property if the current value is null." comment mean?

How can I reset the table used by a DataView at runtime and have all its
bound controls work? Since the DataView is handling the proxying to the
table then surely this should be possible.

-simon
 
Back
Top