How to set grid cell width of DataGrid control?

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.
 
E

Earl

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 = ""
 

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