Datagrid: source from different datatables

  • Thread starter Thread starter William Ryan
  • Start date Start date
W

William Ryan

I'm not totally sure I understand what you want to do, but
I'll give it a try...if not, let me know and I'll see what
I can do...

If you use a SQL Statement that Concatenates the fields ie
SELECT usrCod, usrLastName + ' ' + FirstName
AS 'Full_Name'... from Users.... That will give you the
name combo that you want. You can take your Checkouts
DataTable and base a DataView on it. Each time you switch
the user I don't know if it's in a grid or whatever, you
can set the DataView.Rowfilter = "UsrCode ='" &
actualcodefromControl & "'"

If you use a combo box or a list box or whatever control,
you can manipulate the DisplayMember and ValueMember
properties to show one value, but it still uses another
value internally. You can grab onto that value to filter
the view. You can take your pick of multiple ways to get
the UsrCode value from the DataTable (or you could use a
HashTable for instance, fill it with a DataReader and use
the combobox position as the Key and the UsrCode as the
value, then you could determine UsrCode from the
comboboxes index. These are just a few suggestions, you
can grab that filter value however you want. The main
thing is to set the RowFilter if you use a DataView.

You can also use a Bindingmanager to show the related
records (you'd need to bring out the old DataRelation
again though) and move the bmb's index based on the
control value.

Let me know if this helps..If not, let me know a little
more and I'll see what I can do.

Bill

Good Luck,

W.G. Ryan
www.knowdotnet.com
 
Hi Bill.
In effect, the "problem" is little different. I hope to be more clear below
:-)
Here is a snapshot of data from the 2 tables:

Checkouts:
chkId chkDate chkUseCod
45 12/07/03 221
46 15/08/03 222
48 15/08/03 222
50 16/08/03 221

Users:
usrCod usrName usrLastName
220 John Kellington
221 Frank Perl
222 Luke Sun

As you can see the only datarelation I can set is from Users to Checkouts
(because
usrCod is the master key field and is connected to the child chkUsrCod,
which
contains repeated values). And in fact if I'd like to obtain all checkouts
regarding
a particular user, there is no problem: I can set a data relation as
explained above.

But the problem is "inverted": in practice I need to choose (display) a
Checkout
and see the corresponding User. So the relation is from chkUsrCod to usrCod
(as you can see chkUsrCod isn't a key field, so I can't establish a
datarelation :-(
In other words my relation should be many-to-one!

Back to my interface: I have a tab with 2 pages! On the first page a
datagrid (showing
the "extended" view of Checkouts - i.e. with usrName+usrLastName in the
place
of chkUsrCod). On the 2nd a set of textboxes for editing fields of Checkouts
table.
Datagrid must be readonly so you can only "see" Checkouts but you must
"doubleclick"
on a row for accessing the editing page. Here you can change "original"
values of Checkouts and save them back to db. Obviously also the "original"
value for chkUsrCod (that you must choose from a listbox).

All these controls (datagrid and textboxes) I need to be all (data)bound to
the same dataset/datatable (so I can navigate using just one
bindingmanager). And when made
a change to dataset through textboxes, the same changes occur in the
datagrid.
Then I need to save all to db (using a CommandBuilder??? It's not very
simple using
a JOIN table :-(

So the question is: I want to have two different datatables in my dataset,
one for each Checkouts and Users. So I could navigate in the datagrid and
editing each row using
the tabpage with textboxes bound to the dataset. But "only" in the datagrid
I need
to display the "full name" of the user and not it's ID.

I think it's possibile... if you help me :-)
Bye
Francesco
 
Back
Top