Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have a dataset with 2 tables and a relation between these 2 tables

 

now i show both tables in 2 grids on one form

 

what i want is:

 

when i klick in a row in the 'mastergrid' the 'slavegrid' should show only those records that fit the key in the mastergrid

 

e.g. : customers and orders -->

when i'm at a certain customer in the 'mastergrid', i only whant to see the orders for that customer in the 'slavegrid'

 

here' the code (dataset & relation created in the designer)

 

SqlDataAdapter1.Fill(DataSet11, "master")

SqlDataAdapter2.Fill(DataSet11, "slave")

 

With DataGrid1

.DataSource = DataSet11

.SetDataBinding(DataSet11, "master")

End With

 

With DataGrid2

.DataSource = DataSet11

.SetDataBinding(DataSet11, "slave")

End With

 

 

 

 

how does the

 

slaveGrid_CurrentCellChanged method look like ??

 

or do i have to use a dataview where i set the key explicitly ????

Posted

what is displayed in a datagrid is (usually) defined by the TableStyle property of the grid. You need to define the TableStyle for the Master/Slave_1/Slave_2/etc/etc view you want to show in your grid and assign the MappingName property of each TableStyle to each view. Although when you first start doing this it seems complex and too much hassle, it quickly becomes easy and KewL... check out the DataGrid section here...

 

Windows Forms FAQ

 

 

for lots of really useful info on getting to grips with the DataGrid control

Posted

misunderstanding ??

 

tnx for the reply csharpener, but there must have been some misunderstanding

 

first of all, I doent know how many records are in the master-table, so I cannot create a tablestyle for every record there, and I really think you didn't meen that I should

 

I have TWO GRIDS, and they should be related in that way, so that the 'slavegrid' always shows all records (and only those) belonging to the ACTUAL record of the 'mastergrid'

(e.g. all orders of a customer)

 

I'm not really familiar with tablestyles, but I did use them already, and I doen't think, my problem has something to do with tablestyles

Posted

ok... i think I understand what you mean now...

 

 

Once you have selected a record in the master (grid) you want to show the slave grid with only the records that are related to the selected row in the master (grid)... ?

 

 

one way to do this might be to find the relation field in the master DataSet and filter the slave DataSet based on this value.

 

IE (sorry.. this is C# syntax)

 

private void MyGrid1.CurrentRowChanged(object sender, System.EventArgs e)

{

DataRowView DV = (DataRowView)MyGrid1.BindingContext[DataSet11, "master"].Current;

FilterDataSet2(DV["Row_ID"]);

}

 

private void FilterDataSet2(int row_id)

{

this.DataSet11.Tables["Slave"].DefaultView.RowFilter = "ForeignKeyField = '" + ROW_ID " "'";

}

 

 

maybe someone will translate this to VB? (or have a better suggestion :))

 

CS

Posted

it works, and it doesn't work

 

thanks a lot for your help -

 

even though i'm a little confused now

 

the example works without an error, but the set of records in the slave-grid is not filtered by setting the filterrow-property (at least the grid shows the same set of records as before ...)

 

 

BUT :

 

when I create an extra DataView Object for the slave-table and bind this to the grid IT WO-ORKS

 

thanks again

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...