Jason,
You have to create a DataStyle for the datagrid.
Here is an example of one I use in my WinApp.
private void ConfigureTestPo intDatagrid()
{
DataGridTableSt yle tsTP = new DataGridTableSt yle();
tsTP.MappingNam e = "TestPoints Table";
tsTP.Alternatin gBackColor = SystemColors.Co ntrol;
/* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */
DataGridTextBox Column aliasIDCol = new DataGridTextBox Column();
aliasIDCol.Mapp ingName = "aliasID";
aliasIDCol.Head erText = "Alias ID";
aliasIDCol.Widt h = 80;
tsTP.GridColumn Styles.Add(alia sIDCol);
DataGridTextBox Column nameCol = new DataGridTextBox Column();
nameCol.Mapping Name = "parameterName" ;
nameCol.HeaderT ext = "Test Point Name";
nameCol.Width = 375;
tsTP.GridColumn Styles.Add(name Col);
DataGridTextBox Column fiCol = new DataGridTextBox Column();
fiCol.MappingNa me = "Subsystem" ;
fiCol.HeaderTex t = "Subsystem" ;
fiCol.Width = 95;
fiCol.NullText = "";
tsTP.GridColumn Styles.Add(fiCo l);
DataGridColumnS tyle idCol = new DataGridTextBox Column();
idCol.MappingNa me = "ID";
idCol.Width = 0;
tsTP.GridColumn Styles.Add(idCo l);
testPointDatagr id.TableStyles. Add(tsTP);
}
HTH
"Jason Huang" wrote:
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