DataGrid Width Issue - Please Explain!
Hi All,
I am writing a generic multitable maintenance screen. I have a SplitContainer with a DataGrid in each. This all works fine, however when I go to set the width I get some really bizare results:
When I set it manually all is good:
private void SetGridSizeAndLocation()
{
this.splitContainer1.SuspendLayout();
if (_horizontalSplit)
{
this.splitContainer1.Orientation = Orientation.Horizontal;
this.splitContainer1.SplitterDistance = (this.splitContainer1.Height / 2);
}
else
{
this.splitContainer1.Orientation = Orientation.Vertical;
this.splitContainer1.SplitterDistance = (this.splitContainer1.Width / 2);
}
int width = this.splitContainer1.Panel1.Width - 5;
_parentGrid.Size = new Size(390, 100);
_parentGrid.Refresh();
_childGrid.Size = new Size(390, 100);
_childGrid.Refresh();
this.splitContainer1.ResumeLayout();
}
IMAGE:
http://img154.imageshack.us/img154/7311/1stfs0.png
However if I try to set the width dynamically I get this:
[quote]private void SetGridSizeAndLocation()
{
this.splitContainer1.SuspendLayout();
if (_horizontalSplit)
{
this.splitContainer1.Orientation = Orientation.Horizontal;
this.splitContainer1.SplitterDistance = (this.splitContainer1.Height / 2);
}
else
{
this.splitContainer1.Orientation = Orientation.Vertical;
this.splitContainer1.SplitterDistance = (this.splitContainer1.Width / 2);
}
int width = this.splitContainer1.Panel1.Width - 5;
_parentGrid.Size = new Size(width, 100);
_parentGrid.Refresh();
width = this.splitContainer1.Panel2.Width - 5;
_childGrid.Size = new Size(width, 100);
_childGrid.Refresh();
this.splitContainer1.ResumeLayout();
}
IMAGE:
http://img144.imageshack.us/img144/3523/2ndre6.png
Any ideas woudl really be appreciated. Thank you in advance,
Cya.