Binding DataGrid

  • Thread starter Thread starter PawelR
  • Start date Start date
P

PawelR

Hello group,
I my apps I have two dataGrids - dgParent, dgChild to show rows from two
tables. Tables are relations one to more in dataBase.
I use sqlDataAdater (sdaParent, sdaChild) to fill myDS.
DataSource in dgParent I have set myDS.Tables["Parent"] (for dgChild
myDS.Tables["Child"]);
My questions:
How show in dgChild only rows where show only child for parent selected
in dgParent?
Which event us (double click, leave etc.)?

Maybe someone have any sample with resolving this problem.

Pawe³
 
Cor

Dzieki,
ale jakos nie mam podejscia tego. Fajnie jak bys mial chwile i na to
spojrzal.

Mam dataSet (specyfikowany na podstawie pliku xsd).
W ds dwie tabele Osoba (idOsoba(PK), Imie, Nazwisko ... ) i AdresEmail
(idEmail, idOsoba(FK), Adres). Polaczone sa one za pomoca relacji
OsobaAdresEmail.

Dzieki Twojej radzie do pierwszego dataGrid'u jako dgOsoba.DataSource =
ds.Osoba.DefaultView;
Nastepnie Binduje dane do textBox'ów tbImie.DataBindings.Add(new
Binding("Text", ds.Osoba.DefaultView, "Imie"));

Po dodaniu kolejnego dataGrida - dgEmail.SetDataBinding(ds,
"AdresEmail.idOsoba");
w trakcie dzialania otrzymuje blad "Specified cast is not valid."
jezeli ustawie dgEmail.SetDataBinding(ds, "OsobaAdresEmail.idOsoba"); lub
dgEmail.SetDataBinding(ds, "OsobaAdresEmail");
to jest nastepujacy blad "Cannot create a child list for field
OsobaAdresEmail"
Sprawdzilem typy pól w bazie i dataSet i one sie zgadzaja, o jakie
rzutowanie tu chodzi.

Wielkie dzieki

Pozdrawiam Pawel
Uzytkownik "Cor Ligthert" <[email protected]> napisal w wiadomosci
Pawel,

Is this enough

DataGrid2.SetDataBinding(Ds, "Countries.Regulars");

"Countries.Regulars" is the child in a dataset relation where the first
table is Countries and the second Regulars.

http://msdn.microsoft.com/library/d...frlrfsystemdatadatasetclassrelationstopic.asp

Mam nadzieje ze to pomorze?

Cor
 
Pawel,

I made a sample for you, maybe you can try it. It includes the creation of a
kind of strongly typed dataset.

\\\ needs two datagrids
private void Form1_Load(object sender,
System.EventArgs e)
{
dst ds = new dst();
dataGrid1.DataSource = ds.Polska;
dataGrid2.SetDataBinding (ds, "Polska.drlHolland");
}
}
public class dst : DataSet
{
public dst()
{
this.Tables.Add(dta(new DataTable("Polska")));
this.Tables.Add(dta(new DataTable("Holland")));
DataRelation drlHolland = new DataRelation("drlHolland",
this.Tables["Polska"].Columns["Pawel"],
this.Tables["Holland"].Columns["Pawel"]);
this.Relations.Add(drlHolland);
}
private DataTable dta (DataTable dt)
{
dt.Columns.Add("Pawel");
int total = 10;
if (dt.TableName=="Holland") total = 100;
for (int i=0;i<total;i++)
{
dt.Rows.Add(dt.NewRow());
if (dt.TableName=="Holland")
dt.Rows[0] = i/10;
else
dt.Rows[0]=i;
}
if (dt.TableName=="Holland")
{
dt.Columns.Add("Cor");
for (int i=0;i<total;i++)
{
dt.Rows[1] = i+100;
}
}
return dt;
}
public DataTable Polska {get{return this.Tables[0];}}
public DataTable Holland {get{return this.Tables[1];}}
}
}
///
I hope this helps a little bit?

Cor
 
Back
Top