Hi, Visual Studio 2003
The application Im writing is skinned and therefore i need to be able to
write my own code for manipulating and drawing headers for a data grid
outside of the control.
I created and populated a dataset (source at end of mail) and bound it to a
grid for testing.
For the datagrid, I used a tablestyles object mapped to table "box". I add
gridcolumnstyles for each column and set the 'Icon' column width to 32
I even set it again to 32 as follows at runtime
dataGrid1.TableStyles["box"].GridColumnStyles["Icon"].Width = 32;
Although the cell is 32 pixels high as i wanted, it's only approx 24 pixels
wide. Setting width generally shows the cell shrinking and expanding as i
tested it with a few different values. Is this expected behaviour? Does it
work ok for everyone else?
'Icon' is at column[0] within the grid and I'm planning to paint an icon in
this position.
private void MakeTestDataset()
{
table = new DataTable("box");
DataColumn col = new DataColumn();
col.DataType = System.Type.GetType("System.String");
col.ColumnName = "Icon";
col.ReadOnly = true;
table.Columns.Add(col);
col = new DataColumn();
col.DataType = System.Type.GetType("System.String");
col.ColumnName = "From";
col.ReadOnly = true;
table.Columns.Add(col);
col = new DataColumn();
col.DataType = System.Type.GetType("System.String");
col.ColumnName = "Subject";
col.ReadOnly = true;
table.Columns.Add(col);
col = new DataColumn();
col.DataType = System.Type.GetType("System.DateTime");
col.ColumnName = "Received";
col.ReadOnly = true;
table.Columns.Add(col);
for (int i = 0; i < 10; i++)
{
DataRow row = table.NewRow();
row["Icon"] = "I" + i.ToString();
row["From"] = "From" + i.ToString();
row["Subject"] = "Subject" + i.ToString();
row["Received"] = DateTime.Now.AddDays(i);
table.Rows.Add(row);
}
dataset = new DataSet("Inboxdataset");
dataset.Tables.Add(table);
dataGrid1.SetDataBinding(dataset,"box");
Copied from form initializer
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Alignment =
System.Windows.Forms.HorizontalAlignment.Center;
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.MappingName = "Icon";
this.dataGridTextBoxColumn1.ReadOnly = true;
this.dataGridTextBoxColumn1.Width = 32;