By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 1,912 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

Tie one grid to another (master/detail)

P: n/a
Hey All,

Working with the .Net data has been the hardest part of my
transition. It just doesn't seem very intuitive.

I want to have a master/detail relationship between 2 grids. When the
user navigates grid 1, only the details for that record appear in grid
2. How?

I created a datasource and added the 2 tables. The relationship
between the two tables was created. Now what? How do I get the first
grid to act like a filter for the second grid?

I am using devexpress grids so hopefully this isn't grid specific.

TIA

~GINA_M~

Jun 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I usually use DataGridView in very rare cases when all that's needed is to
display some single table. Anything more complicated than that, and this
control falls out of the question.

For your task I'd use a pare of regular ListView controls, which I'd
populate programmatically.

SqlConnection connection = new SqlConnection( connectionString );
connection.Open();

SqlCommand cmd1 = new SqlCommand( "select * from table1", connection );
SqlDataReader reader = cmd1.ExecuteReader();

while( reader.Read() )
{
// add rows to ListView1:
ListViewItem item = listView1.Items.Add( (int)reader[0] ); // Say, some
record ID
item.Subitems.Add( (string)reader[1] ); // record description
}

reader.Close();

// Now handle the selection change in ListView1 and populate ListView2:
void listView1_SelectionChanged( ... ) // or whatever the event's name
{
SqlCommand cmd2 = new SqlCommand( "select * from table2 where ID = " +
listView1.SelectedItems[0].Text, connection );
reader = cmd2.ExecuteReader();

while( reader.Read() )
{
// add rows to ListView2:
ListViewItem item = listView2.Items.Add( (int)reader[0] ); // some
record ID
item.Subitems.Add( (string)reader[1] ); // record description
}
reader.Close();
}

// On application exit:
connection.Close();

"Gina_Marano" <gi*******@gmail.comwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
Hey All,

Working with the .Net data has been the hardest part of my
transition. It just doesn't seem very intuitive.

I want to have a master/detail relationship between 2 grids. When the
user navigates grid 1, only the details for that record appear in grid
2. How?

I created a datasource and added the 2 tables. The relationship
between the two tables was created. Now what? How do I get the first
grid to act like a filter for the second grid?

I am using devexpress grids so hopefully this isn't grid specific.

TIA

~GINA_M~

Jun 16 '07 #2

P: n/a
Hello Gina_Marano,

See there http://www.syncfusion.com/FAQ/winfor...44c.aspx#q780q

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

GHey All,
G>
GWorking with the .Net data has been the hardest part of my
Gtransition. It just doesn't seem very intuitive.
G>
GI want to have a master/detail relationship between 2 grids. When the
Guser navigates grid 1, only the details for that record appear in
Ggrid 2. How?
G>
GI created a datasource and added the 2 tables. The relationship
Gbetween the two tables was created. Now what? How do I get the first
Ggrid to act like a filter for the second grid?
G>
GI am using devexpress grids so hopefully this isn't grid specific.
G>
GTIA
G>
G~GINA_M~
G>
Jun 16 '07 #3

P: n/a
Thanks Guys for giving it a try. I will look into Ashot's solution.

~Gina_M~

Jun 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.