H
Hexman
I was going along fine in my test to see how to manipulate the
DataGrid (dgTrans) and its columns. I have a single form with one
DataGrid (dgTrans) on it. The code I have in my form load event is:
Dim dt As New DataTable("WorkOrders")
Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn
dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt
Dim gcolSelect As New DataGridBoolColumn
With gcolSelect
.Width = 15
.HeaderText = "Select"
.MappingName = "colSel"
End With
Dim gcolStatus As New DataGridTextBoxColumn
With gcolStatus
.Width = 15
.HeaderText = "Status"
.MappingName = "colStatus"
End With
Dim gcolWO As New DataGridTextBoxColumn
With gcolWO
.Width = 40
.HeaderText = "Work Order"
.MappingName = "colWO"
End With
Dim gcolEmployee As New DataGridTextBoxColumn
With gcolEmployee
.Width = 60
.HeaderText = "Employee"
.MappingName = "colEmployee"
End With
Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)
dt.Rows.Add(New Object() {False, "Open", "WO123123", "Hexman"})
dt.Rows.Add(New Object() {False, "Open", "WO123234", "S. Jones"})
dt.Rows.Add(New Object() {False, "QA", "WO123345", "B. Daley"})
dt.Rows.Add(New Object() {False, "Closed", "WO123456", "K. Genns"})
dt.Rows.Add(New Object() {False, "Open", "WO123567", "Superman"})
----------------------------------------------------------------------------------------------------------------------------------
As you can see I wanted to change the header text and width of the
grid coulumn. They are not set as I expected. The columns when
displayed are "colSel, Column1, Column2, Column3" instead of "Select,
Status, Work Order, Employee". Also the widths are not set.
I've got this working this far from Cor's Website, but I'm now stuck.
I thought I've tried everything. (I'm sure I haven't).
One other issue I'm seeing in the near future is how do I access (as
an example) a datagrid column width. In the above code it is changed
before the columns are added to the grid table styles. After the fact
how do you access that attribute? Something like:
dgTrans.TableStyles(ts).GridColumnStyles(gcolEmployee).width = 42
Need some help here.
Thanks,
Hexman
DataGrid (dgTrans) and its columns. I have a single form with one
DataGrid (dgTrans) on it. The code I have in my form load event is:
Dim dt As New DataTable("WorkOrders")
Dim colSelect As New DataColumn
Dim colStatus As New DataColumn
Dim colWO As New DataColumn
Dim colEmployee As New DataColumn
dt.Columns.Add("colSel", GetType(System.Boolean))
dt.Columns.Add(colStatus)
dt.Columns.Add(colWO)
dt.Columns.Add(colEmployee)
dgTrans.DataSource = dt
Dim gcolSelect As New DataGridBoolColumn
With gcolSelect
.Width = 15
.HeaderText = "Select"
.MappingName = "colSel"
End With
Dim gcolStatus As New DataGridTextBoxColumn
With gcolStatus
.Width = 15
.HeaderText = "Status"
.MappingName = "colStatus"
End With
Dim gcolWO As New DataGridTextBoxColumn
With gcolWO
.Width = 40
.HeaderText = "Work Order"
.MappingName = "colWO"
End With
Dim gcolEmployee As New DataGridTextBoxColumn
With gcolEmployee
.Width = 60
.HeaderText = "Employee"
.MappingName = "colEmployee"
End With
Dim ts As New DataGridTableStyle
ts.GridColumnStyles.Add(gcolSelect)
ts.GridColumnStyles.Add(gcolStatus)
ts.GridColumnStyles.Add(gcolWO)
ts.GridColumnStyles.Add(gcolEmployee)
dgTrans.TableStyles.Add(ts)
dt.Rows.Add(New Object() {False, "Open", "WO123123", "Hexman"})
dt.Rows.Add(New Object() {False, "Open", "WO123234", "S. Jones"})
dt.Rows.Add(New Object() {False, "QA", "WO123345", "B. Daley"})
dt.Rows.Add(New Object() {False, "Closed", "WO123456", "K. Genns"})
dt.Rows.Add(New Object() {False, "Open", "WO123567", "Superman"})
----------------------------------------------------------------------------------------------------------------------------------
As you can see I wanted to change the header text and width of the
grid coulumn. They are not set as I expected. The columns when
displayed are "colSel, Column1, Column2, Column3" instead of "Select,
Status, Work Order, Employee". Also the widths are not set.
I've got this working this far from Cor's Website, but I'm now stuck.
I thought I've tried everything. (I'm sure I haven't).
One other issue I'm seeing in the near future is how do I access (as
an example) a datagrid column width. In the above code it is changed
before the columns are added to the grid table styles. After the fact
how do you access that attribute? Something like:
dgTrans.TableStyles(ts).GridColumnStyles(gcolEmployee).width = 42
Need some help here.
Thanks,
Hexman