How to set grid cell width of DataGrid control?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, friends,

In my VC# Windows app, I have a DataGrid with a DataTable as its DataSource.
I need to programmtically set the grid cell width of this DataGrid control
since columns in DataTable could be different each time. I looked MSDN up and
down, no luck.

Could any one give me some reference paper or sample code? Thanks a lot.
 
You have to design a new tablestyle and use that with the column properties
you assign, like so:

Dim tblStyle As New DataGridTableStyle
tblStyle.MappingName = "dtEmployees"
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(tblStyle)
Dim tbc1 As DataGridTextBoxColumn =
CType(tblStyle.GridColumnStyles("EmployeeLastName"), DataGridTextBoxColumn)
tbc1.Alignment = HorizontalAlignment.Left
tbc1.HeaderText = "Last"
tbc1.Width = 90
tbc1.NullText = ""
 
Back
Top