datagrid cell width problem

J

Jason Huang

Hi,

In my C# Windows form project.
I am wondering can we manually define the width of a cell in a DataGrid?
Thanks for help.


Jason
 
G

Guest

Jason,

You have to create a DataStyle for the datagrid.

Here is an example of one I use in my WinApp.

private void ConfigureTestPointDatagrid()
{
DataGridTableStyle tsTP = new DataGridTableStyle();
tsTP.MappingName = "TestPoints Table";
tsTP.AlternatingBackColor = SystemColors.Control;

/* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */

DataGridTextBoxColumn aliasIDCol = new DataGridTextBoxColumn();
aliasIDCol.MappingName = "aliasID";
aliasIDCol.HeaderText = "Alias ID";
aliasIDCol.Width = 80;
tsTP.GridColumnStyles.Add(aliasIDCol);

DataGridTextBoxColumn nameCol = new DataGridTextBoxColumn();
nameCol.MappingName = "parameterName";
nameCol.HeaderText = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumnStyles.Add(nameCol);

DataGridTextBoxColumn fiCol = new DataGridTextBoxColumn();
fiCol.MappingName = "Subsystem";
fiCol.HeaderText = "Subsystem";
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumnStyles.Add(fiCol);

DataGridColumnStyle idCol = new DataGridTextBoxColumn();
idCol.MappingName = "ID";
idCol.Width = 0;
tsTP.GridColumnStyles.Add(idCol);

testPointDatagrid.TableStyles.Add(tsTP);
}

HTH
 
J

Jason Huang

Thansk White.
If my DataGrid's name is "dataGrid1", how do I implement your function for
my datagrid?
 
J

Jason Huang

tsTP.MappingName = mytb.TableName.ToString();

Jason Huang said:
Thansk White.
If my DataGrid's name is "dataGrid1", how do I implement your function for
my datagrid?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top