Y
yzhao
Hello, Gurus,
I would like the DataGrid to display just one of the tables in my
DataSet. So I set AllowNevigate to false on the datagrid. I also want
to reduce the row header to 10 so it doesn't take much space. However,
the row header would just stay at a minimum of 30! If I take away the
DataRelation then it will reduce to any width as I wish.
Below is a snapshot of my code:
private void Form1_Load(object sender, System.EventArgs e)
{
MyTable1 = new DataTable("Table1");
MyTable2 = new DataTable("Table2");
PopulateTable();
this.mySet = new DataSet();
this.mySet.Tables.Add(MyTable1);
this.mySet.Tables.Add(MyTable2);
DataRelation relation = new DataRelation("two
tables",MyTable1.Columns[0],
MyTable2.Columns[0]);
// if I remove the line below everything works fine, but I need the
relationship!!
this.mySet.Relations.Add(relation);
this.dataGrid1.AllowNavigation = false;
this.dataGrid1.DataSource = this.mySet;
this.dataGrid1.DataMember = "Table1";
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = "Table1";
DataGridColumnStyle cs = new DataGridTextBoxColumn();
cs.MappingName = "Name";
style.GridColumnStyles.Add(cs);
cs = new DataGridTextBoxColumn();
cs.MappingName = "Company";
style.GridColumnStyles.Add(cs);
style.RowHeaderWidth = 10;
this.dataGrid1.TableStyles.Add(style);
}
private void PopulateTable()
{
DataColumn col1 = new DataColumn("Name");
MyTable1.Columns.Add(col1);
DataColumn col2 = new DataColumn("Company");
MyTable1.Columns.Add(col2);
for(int i= 0; i<3; i++)
{
DataRow dr = MyTable1.NewRow();
dr[0]= ("name" + i);
dr[1] = ("Company" + i);
MyTable1.Rows.Add(dr);
}
DataColumn col3 = new DataColumn("Name");
MyTable2.Columns.Add(col3);
DataColumn col4 = new DataColumn("Phone");
MyTable2.Columns.Add(col4);
for(int i= 0; i<3; i++)
{
DataRow dr = MyTable2.NewRow();
dr[0]= ("name" + i);
dr[1] = ("Company" + i);
MyTable2.Rows.Add(dr);
}
}
I read on another post that somebody couldn't shorten the
rowheaderwidth on one datagrid but could on another. Don't know whether
he has a DataRelation on the tables.
http://groups-beta.google.com/group...+rowheaderwidth&rnum=1&hl=en#818023502751d8c3
Is this a bug?
I would like the DataGrid to display just one of the tables in my
DataSet. So I set AllowNevigate to false on the datagrid. I also want
to reduce the row header to 10 so it doesn't take much space. However,
the row header would just stay at a minimum of 30! If I take away the
DataRelation then it will reduce to any width as I wish.
Below is a snapshot of my code:
private void Form1_Load(object sender, System.EventArgs e)
{
MyTable1 = new DataTable("Table1");
MyTable2 = new DataTable("Table2");
PopulateTable();
this.mySet = new DataSet();
this.mySet.Tables.Add(MyTable1);
this.mySet.Tables.Add(MyTable2);
DataRelation relation = new DataRelation("two
tables",MyTable1.Columns[0],
MyTable2.Columns[0]);
// if I remove the line below everything works fine, but I need the
relationship!!
this.mySet.Relations.Add(relation);
this.dataGrid1.AllowNavigation = false;
this.dataGrid1.DataSource = this.mySet;
this.dataGrid1.DataMember = "Table1";
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = "Table1";
DataGridColumnStyle cs = new DataGridTextBoxColumn();
cs.MappingName = "Name";
style.GridColumnStyles.Add(cs);
cs = new DataGridTextBoxColumn();
cs.MappingName = "Company";
style.GridColumnStyles.Add(cs);
style.RowHeaderWidth = 10;
this.dataGrid1.TableStyles.Add(style);
}
private void PopulateTable()
{
DataColumn col1 = new DataColumn("Name");
MyTable1.Columns.Add(col1);
DataColumn col2 = new DataColumn("Company");
MyTable1.Columns.Add(col2);
for(int i= 0; i<3; i++)
{
DataRow dr = MyTable1.NewRow();
dr[0]= ("name" + i);
dr[1] = ("Company" + i);
MyTable1.Rows.Add(dr);
}
DataColumn col3 = new DataColumn("Name");
MyTable2.Columns.Add(col3);
DataColumn col4 = new DataColumn("Phone");
MyTable2.Columns.Add(col4);
for(int i= 0; i<3; i++)
{
DataRow dr = MyTable2.NewRow();
dr[0]= ("name" + i);
dr[1] = ("Company" + i);
MyTable2.Rows.Add(dr);
}
}
I read on another post that somebody couldn't shorten the
rowheaderwidth on one datagrid but could on another. Don't know whether
he has a DataRelation on the tables.
http://groups-beta.google.com/group...+rowheaderwidth&rnum=1&hl=en#818023502751d8c3
Is this a bug?