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~