471,066 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Datagrid column width not as requested?

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;
Jul 9 '07 #1
0 1263

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Prateek | last post: by
9 posts views Thread by web1110 | last post: by
2 posts views Thread by CSL | last post: by
4 posts views Thread by Steve | last post: by
6 posts views Thread by Agnes | last post: by
2 posts views Thread by cj | last post: by
2 posts views Thread by =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.