C
ColoradoGeiger
I have a datagrid view that I have made in the designer. When
compiled and data is loaded into it, it looks great.
I have this on page 1 of a tab control. Pages 2 through N are created
on the fly in a loop, the code for that loop is below, as with the
datagrids on their pages. The code below tries to copy all properties
from the grid that looks good (dgridMaster) to the one that I am
creating on the fly... but it doesn't work. I am missing something?
-----------------------------------------------------------------------------
TabPage tab = new TabPage();
DataGridView dgv = new DataGridView();
dgv.DataSource = MyMagicDLL.GetTableData();
dgv.Name = dtCurrent.ToShortDateString();
dgv.Location = dgridMaster.Location;
dgv.Size = dgridMaster.Size;
dgv.SelectionMode = dgridMaster.SelectionMode;
dgv.ReadOnly = dgridMaster.ReadOnly;
dgv.DefaultCellStyle = dgridMaster.DefaultCellStyle;
dgv.AlternatingRowsDefaultCellStyle =
dgridMaster.AlternatingRowsDefaultCellStyle;
dgv.ColumnHeadersDefaultCellStyle =
dgridMaster.ColumnHeadersDefaultCellStyle;
dgv.RowHeadersDefaultCellStyle =
dgridMaster.RowHeadersDefaultCellStyle;
dgv.AutoSizeColumnsMode = dgridMaster.AutoSizeColumnsMode;
dgv.ScrollBars = dgridMaster.ScrollBars;
for (i = 0; i <= (dgv.Columns.Count - 1); i++)
{
dgv.Columns.SortMode = DataGridViewColumnSortMode.NotSortable;
}
tab.Controls.Add(dgv);
tab.Name = tab.Text = "My table"
TabControl.TabPages.Add(tab);
-----------------------------------------------------------------------------
The differences i notice:
1. The grid created on the fly has sortable columns. And because of
this it takes up more space in the X axis since beside each Header
cell there is space to the right for the up or down arrow.
2. The size looks good until i maximize the window. The original grid
adjust because it's anchor properties are set. But I lose my scroll
bars on my new grid when I add the line
dgv.Anchor = dgridMaster.Anchor;
Any ideas?
Jason
compiled and data is loaded into it, it looks great.
I have this on page 1 of a tab control. Pages 2 through N are created
on the fly in a loop, the code for that loop is below, as with the
datagrids on their pages. The code below tries to copy all properties
from the grid that looks good (dgridMaster) to the one that I am
creating on the fly... but it doesn't work. I am missing something?
-----------------------------------------------------------------------------
TabPage tab = new TabPage();
DataGridView dgv = new DataGridView();
dgv.DataSource = MyMagicDLL.GetTableData();
dgv.Name = dtCurrent.ToShortDateString();
dgv.Location = dgridMaster.Location;
dgv.Size = dgridMaster.Size;
dgv.SelectionMode = dgridMaster.SelectionMode;
dgv.ReadOnly = dgridMaster.ReadOnly;
dgv.DefaultCellStyle = dgridMaster.DefaultCellStyle;
dgv.AlternatingRowsDefaultCellStyle =
dgridMaster.AlternatingRowsDefaultCellStyle;
dgv.ColumnHeadersDefaultCellStyle =
dgridMaster.ColumnHeadersDefaultCellStyle;
dgv.RowHeadersDefaultCellStyle =
dgridMaster.RowHeadersDefaultCellStyle;
dgv.AutoSizeColumnsMode = dgridMaster.AutoSizeColumnsMode;
dgv.ScrollBars = dgridMaster.ScrollBars;
for (i = 0; i <= (dgv.Columns.Count - 1); i++)
{
dgv.Columns.SortMode = DataGridViewColumnSortMode.NotSortable;
}
tab.Controls.Add(dgv);
tab.Name = tab.Text = "My table"
TabControl.TabPages.Add(tab);
-----------------------------------------------------------------------------
The differences i notice:
1. The grid created on the fly has sortable columns. And because of
this it takes up more space in the X axis since beside each Header
cell there is space to the right for the up or down arrow.
2. The size looks good until i maximize the window. The original grid
adjust because it's anchor properties are set. But I lose my scroll
bars on my new grid when I add the line
dgv.Anchor = dgridMaster.Anchor;
Any ideas?
Jason