datagridview is not updating in master-detail relation

datagridview is not updating in master-detail relation

Post by Dirk » Sat, 17 Jun 2006 19:25:29


I setup a simple database with a master and a detail table. Both are
connected via a datarelation. Data of each table is shown in a
datagridview (dgLektion and dgLektionlernkarten). When I start the app
for the first time, everything works fine: all master rows are shown
in dgLektion and the appropriate child rows of the first selected
master row are shown in dgLektionlernkarten.

But if I click e.g. on the 2nd row of the master table,
dgLektionlernkarten is not updated and therefore still shows the child
rows of the previous selected master row.

Even more strange for me is that if I click on the column header in
dgLektion and so change the order of the master rows, than
dgLektionlernkarten is updating correctly and showing the child rows
for the now topmost master row.

Can anyone give me a hint what I am doing wrong?

Code:

SqlCommand selCommandLektion = conn.CreateCommand();
selCommandLektion.CommandText = "SELECT * FROM Lektion";
SqlDataAdapter daLektion = new SqlDataAdapter(selCommandLektion);
daLektion.Fill(dsLCard, "Lektion");

SqlCommand selCommandLektionLernkarten = conn.CreateCommand();
selCommandLektionLernkarten.CommandText = "SELECT * FROM
LektionLernkarten";
SqlDataAdapter daLektionLernkarten = new
SqlDataAdapter(selCommandLektionLernkarten);
daLektionLernkarten.Fill(dsLCard, "LektionLernkarten");


dsLCard.Relations.Add("relLektion_LektionLernkarten",
dsLCard.Tables["Lektion"].Columns["ID"],
dsLCard.Tables["LektionLernkarten"].Columns["IDLektion"]);

dgLektion.DataSource = dsLCard.Tables["Lektion"];
dgLektionLernkarten.DataSource =
dsLCard.Tables["Lektion"].DefaultView;
dgLektionLernkarten.DataMember = "relLektion_LektionLernkarten";


Thanks
Dirk