Datagrid Column widths

  • Thread starter Thread starter Paul Ilacqua
  • Start date Start date
P

Paul Ilacqua

I'm filling the datagrid with no problem but I do not see a columnwidth
property anywhere. How do you set the columnwidth property of the datagrid
columns in code or manually?
Thank you.

Paul
 
One of the properties is called TableStyles. From there you can define all
the properties of each column.
 
This grid is populated with a data adapter... IE

With grd_inventory

..SetDataBinding(ds_Work, "Line Summary")

..BackColor = System.Drawing.Color.Khaki

..CaptionText = "Line Summary"

End With

Can I set the column width's in here somewhere? They don't seem to work
manually.
 
hi,

i have been strugling with this problem to i can give you somme code of my
project i hop it helps

Private Sub AddCustomDataTableStyle3()

Dim ts1 As New DataGridTableStyle()

ts1.MappingName = "Digitaal"

ts1.ForeColor() = Color.Black

ts1.AlternatingBackColor = System.Drawing.Color.LightGray

ts1.BackColor = System.Drawing.Color.DarkGray

ts1.ForeColor = System.Drawing.Color.Black

ts1.GridLineColor = System.Drawing.Color.Black

ts1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None

ts1.HeaderBackColor = System.Drawing.Color.Silver

ts1.HeaderForeColor = System.Drawing.Color.Black

ts1.LinkColor = System.Drawing.Color.Navy

ts1.SelectionBackColor = System.Drawing.Color.Navy

ts1.SelectionForeColor = System.Drawing.Color.White

//This part sets up the wole datagridstyle

Dim boolCol As New DataGridBoolColumn()

boolCol.MappingName = "State"

boolCol.HeaderText = ""

boolCol.Width = 15

ts1.GridColumnStyles.Add(boolCol)

Dim NameCol As New DataGridTextBoxColumn()

NameCol.MappingName = "Channel"

NameCol.HeaderText = "Chan"

NameCol.Width = 40

ts1.GridColumnStyles.Add(NameCol)

DataGrid3.TableStyles.Add(ts1)

TablesAlreadyAdded = True

Dim ChannelCol As New DataGridTextBoxColumn()

ChannelCol.MappingName = "Name"

ChannelCol.HeaderText = "Name"

ChannelCol.Width = 100

ts1.GridColumnStyles.Add(ChannelCol)

DataGrid3.TableStyles.Add(ts1)

TablesAlreadyAdded = True

//this part ads the collumn 1 chechbox collumn, and 2 textbox collumns

Private Sub MakeDataSe3t()

myDataSet3 = New DataSet("myDataSet")

Dim cont As New DataTable("Digitaal")

Dim Name As New DataColumn("Name", GetType(String))

Dim Channel As New DataColumn("Channel")

Dim Status As New DataColumn("State", GetType(Boolean))

cont.Columns.Add(Status)

cont.Columns.Add(Name)

cont.Columns.Add(Channel)

myDataSet3.Tables.Add(cont)

Dim newRow1 As DataRow

For inti = 0 To 15

newRow1 = cont.NewRow()

newRow1("Name") = dchanName(inti + 1)

cont.Rows.Add(newRow1)

cont.Rows(inti)("Channel") = inti + 1

cont.Rows(inti)("State") = (False)

Next inti

End Sub

i don't fill up the grid by coupling it with a database, but fil it like the
above way
what's important, is that you use the correct mappingname to link yourre
dataset to the datatable.

I hope it helped

kind regards Maarten
 
Back
Top