Cannot change DataGrid.RowHeaderWidth to less than 30 when there is a DataRelation on the datasource

  • Thread starter Thread starter yzhao
  • Start date Start date
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?
 
DataGrid.RowHeaderWidth

I have the exact same problem that you describe. I have a DataGrid bound to a DataRelation where AllowNavigation is set to false. I cannot set the RowHeaderWidth property to less than 30. Were you able to find a solution?
 
Hey I think I solved this one

Looking behind the scenes on this one it goes and looks at the Current Table style for the grid which also has a RowHeaderWidth property which overrides the default if a new style is applied.

So when the new table style is created and initilised set this property to the grids one... Worked for me..:)

eg>
dim oTStyle as new DataGridTableStyle
oTStyle.RowHeaderWidth = dgGrid.RowHeaderWidth

CooPzZ
 
Back
Top