sanders720
Programmer
Simple Question, how do I get my data in the datagrid? Full code below. This data is not derived from a database, but properties from our CAD package, which will eventually be synchronized with data. For now, I am trying to firgue out how to manipulate the CAD data. However, is there a strategy to pull a conventional data source into the same datagrid?
So, question 1 - how can I populate the data, and
question 2 - can I pull the data from a different source into the same datagrid?
Thanks in advance for the help!
' Add Rows
Dim dr As DataRow
dr("id") = 0
dr("Item") = 0.ToString(PN, RPN, L, RSP, PDesc, MFGBY, REV, MFGCODE, MACODE, MAT, FIN, DES, RENMATP)
dt.Rows.Add(dr)
DataGrid1.DataSource = dt
DataGrid1.AllowSorting = True
Public Sub PopulateDataGrid1()
' Add Column Data
' Part No.
Dim PN As String
If Len(oProp3(2).Value + "") > 0 Then
PN = oProp3(2).Value
Else
PN = ""
End If
' Reference Part No.
Dim RPN As String
If Len(oProp4(7).Value + "") > 0 Then
RPN = oProp4(7).Value
Else
RPN = ""
End If
' Length
Dim L As Single
If Len(oProp4(8).Value) > 0 Then
L = oProp4(8).Value
Else
L = 0
End If
' Recommended Spare Part
Dim RSP As Boolean
If Len(oProp4(6).Value) > 0 Then
RSP = oProp4(6).Value
Else
RSP = False
End If
' Part Description
Dim PDesc As String
If (Len(oProp3(14).Value + "") > 0) Or (Len(oProp3(3).Value + "") > 0) Then
PDesc = oProp3(14).Value & " " & oProp3(3).Value
Else
PDesc = ""
End If
' Manufactured By
Dim MFGBY As String
If Len(oProp3(15).Value + "") > 0 Then
MFGBY = oProp3(15).Value
Else
MFGBY = ""
End If
' Revision
Dim REV As String
If Len(oProp1(7).Value + "") > 0 Then
REV = oProp1(7).Value
Else
REV = ""
End If
' Manufacturer Code
Dim MFGCODE As String
If Len(oProp4(5).Value + "") > 0 Then
MFGCODE = oProp4(5).Value
Else
MFGCODE = ""
End If
' Material Code
Dim MACODE As String
If Len(oProp4(2).Value + "") > 0 Then
MACODE = oProp4(2).Value
Else
MACODE = ""
End If
' Material Description
Dim MAT As String
If Len(oProp4(3).Value + "") > 0 Then
MAT = oProp4(3).Value
Else
MAT = ""
End If
' Part Finish
Dim FIN As String
If Len(oProp4(1).Value + "") > 0 Then
FIN = oProp4(1).Value
Else
FIN = ""
End If
' Designer
Dim DES As String
If Len(oProp1(3).Value + "") > 0 Then
DES = oProp1(3).Value
Else
DES = ""
End If
' Rendered Material / Property
Dim RENMATP As String
If Len(oProp3(10).Value + "") > 0 Then
RENMATP = oProp3(10).Value
Else
RENMATP = ""
End If
' Add Columns
Dim tableStyle As New DataGridTableStyle
' Part No.
Dim column As New DataGridTextBoxColumn
column.MappingName = "pn"
column.HeaderText = "Part Number"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Reference Part No.
column = New DataGridTextBoxColumn
column.MappingName = "rpn"
column.HeaderText = "Reference Part Number"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Length
column = New DataGridTextBoxColumn
column.MappingName = "l"
column.HeaderText = "Length"
column.Width = 13
tableStyle.GridColumnStyles.Add(column)
' Recommended Spare Part
column = New DataGridTextBoxColumn
column.MappingName = "rsp"
column.HeaderText = "RSP"
column.Width = 7
tableStyle.GridColumnStyles.Add(column)
' Part Description
column = New DataGridTextBoxColumn
column.MappingName = "pdesc"
column.HeaderText = "Part Description"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Manufactured By
column = New DataGridTextBoxColumn
column.MappingName = "mfgby"
column.HeaderText = "Manufactured By"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Revision
column = New DataGridTextBoxColumn
column.MappingName = "rev"
column.HeaderText = "Revision"
column.Width = 7
tableStyle.GridColumnStyles.Add(column)
' Manufacturer Code
column = New DataGridTextBoxColumn
column.MappingName = "mfgcode"
column.HeaderText = "Manufacturer Code"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Material Code
column = New DataGridTextBoxColumn
column.MappingName = "macode"
column.HeaderText = "Material Code"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Material Description
column = New DataGridTextBoxColumn
column.MappingName = "mat"
column.HeaderText = "Material Description"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Part Finish
column = New DataGridTextBoxColumn
column.MappingName = "fin"
column.HeaderText = "Part Finish"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Designer
column = New DataGridTextBoxColumn
column.MappingName = "des"
column.HeaderText = "Designer"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Rendered Material / Property
column = New DataGridTextBoxColumn
column.MappingName = "renmatp"
column.HeaderText = "Material Property"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
tableStyle.MappingName = "MetroParts"
DataGrid1.TableStyles.Add(tableStyle)
' Define Data Table
Dim dt As DataTable = New DataTable
Dim dc As DataColumn
' Add Columns
'Part Number
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "pn"
dc.AutoIncrement = False
dc.Caption = "Part Number"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Reference Part No.
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "rpn"
dc.AutoIncrement = False
dc.Caption = "Reference Part Number"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Length
dc = New DataColumn
dc.DataType = System.Type.GetType("System.Single")
dc.ColumnName = "l"
dc.AutoIncrement = False
dc.Caption = "Length"
dc.ReadOnly = False
dc.Unique = False
' Recommended Spare Part
dc = New DataColumn
dc.DataType = System.Type.GetType("System.Boolean")
dc.ColumnName = "rsp"
dc.AutoIncrement = False
dc.Caption = "Length"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Part Description
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "pdesc"
dc.AutoIncrement = False
dc.Caption = "Part Description"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Manufactured By
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "mfgby"
dc.AutoIncrement = False
dc.Caption = "Manufactured By"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Revision
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "rev"
dc.AutoIncrement = False
dc.Caption = "Revision"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Manufacturer Code
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "mfgcode"
dc.AutoIncrement = False
dc.Caption = "Manufacturer Code"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Material Code
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "macode"
dc.AutoIncrement = False
dc.Caption = "Material Code"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Material
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "mat"
dc.AutoIncrement = False
dc.Caption = "Material"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Finish
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "fin"
dc.AutoIncrement = False
dc.Caption = "Finish"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Designer
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "des"
dc.AutoIncrement = False
dc.Caption = "Designer"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Rendered Material / Property
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "renmatp"
dc.AutoIncrement = False
dc.Caption = "Material Property"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Define Dataset
Dim ds As New DataSet
ds.Tables.Add(dt)
' Add Rows
Dim dr As DataRow
dr("id") = 0
dr("Item") = 0.ToString(PN, RPN, L, RSP, PDesc, MFGBY, REV, MFGCODE, MACODE, MAT, FIN, DES, RENMATP)
dt.Rows.Add(dr)
DataGrid1.DataSource = dt
DataGrid1.AllowSorting = True
'' Add Columns - simpler methodology worked great!
'dt.Columns.Add("Part Number", GetType(System.String))
'dt.Columns.Add("Reference Part Number", GetType(System.String))
'dt.Columns.Add("Length", GetType(System.Single))
'dt.Columns.Add("RSP", GetType(System.Boolean))
'dt.Columns.Add("Part Description", GetType(System.String))
'dt.Columns.Add("Manufactured By", GetType(System.String))
'dt.Columns.Add("Revision", GetType(System.String))
'dt.Columns.Add("Manufacturer Code", GetType(System.String))
'dt.Columns.Add("Material Code", GetType(System.String))
'dt.Columns.Add("Material Description", GetType(System.String))
'dt.Columns.Add("Part Finish", GetType(System.String))
'dt.Columns.Add("Designer", GetType(System.String))
'dt.Columns.Add("Material Property", GetType(System.String))
'' Add Rows
'dt.Rows.Add(New String() {PN, RPN, L, RSP, PDesc, MFGBY, REV, MFGCODE, MACODE, MAT, FIN, DES, RENMATP})
'' Update Data to DataGrid1
'DataGrid1.DataSource = dt
'DataGrid1.AllowSorting = True
End Sub
So, question 1 - how can I populate the data, and
question 2 - can I pull the data from a different source into the same datagrid?
Thanks in advance for the help!
' Add Rows
Dim dr As DataRow
dr("id") = 0
dr("Item") = 0.ToString(PN, RPN, L, RSP, PDesc, MFGBY, REV, MFGCODE, MACODE, MAT, FIN, DES, RENMATP)
dt.Rows.Add(dr)
DataGrid1.DataSource = dt
DataGrid1.AllowSorting = True
Public Sub PopulateDataGrid1()
' Add Column Data
' Part No.
Dim PN As String
If Len(oProp3(2).Value + "") > 0 Then
PN = oProp3(2).Value
Else
PN = ""
End If
' Reference Part No.
Dim RPN As String
If Len(oProp4(7).Value + "") > 0 Then
RPN = oProp4(7).Value
Else
RPN = ""
End If
' Length
Dim L As Single
If Len(oProp4(8).Value) > 0 Then
L = oProp4(8).Value
Else
L = 0
End If
' Recommended Spare Part
Dim RSP As Boolean
If Len(oProp4(6).Value) > 0 Then
RSP = oProp4(6).Value
Else
RSP = False
End If
' Part Description
Dim PDesc As String
If (Len(oProp3(14).Value + "") > 0) Or (Len(oProp3(3).Value + "") > 0) Then
PDesc = oProp3(14).Value & " " & oProp3(3).Value
Else
PDesc = ""
End If
' Manufactured By
Dim MFGBY As String
If Len(oProp3(15).Value + "") > 0 Then
MFGBY = oProp3(15).Value
Else
MFGBY = ""
End If
' Revision
Dim REV As String
If Len(oProp1(7).Value + "") > 0 Then
REV = oProp1(7).Value
Else
REV = ""
End If
' Manufacturer Code
Dim MFGCODE As String
If Len(oProp4(5).Value + "") > 0 Then
MFGCODE = oProp4(5).Value
Else
MFGCODE = ""
End If
' Material Code
Dim MACODE As String
If Len(oProp4(2).Value + "") > 0 Then
MACODE = oProp4(2).Value
Else
MACODE = ""
End If
' Material Description
Dim MAT As String
If Len(oProp4(3).Value + "") > 0 Then
MAT = oProp4(3).Value
Else
MAT = ""
End If
' Part Finish
Dim FIN As String
If Len(oProp4(1).Value + "") > 0 Then
FIN = oProp4(1).Value
Else
FIN = ""
End If
' Designer
Dim DES As String
If Len(oProp1(3).Value + "") > 0 Then
DES = oProp1(3).Value
Else
DES = ""
End If
' Rendered Material / Property
Dim RENMATP As String
If Len(oProp3(10).Value + "") > 0 Then
RENMATP = oProp3(10).Value
Else
RENMATP = ""
End If
' Add Columns
Dim tableStyle As New DataGridTableStyle
' Part No.
Dim column As New DataGridTextBoxColumn
column.MappingName = "pn"
column.HeaderText = "Part Number"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Reference Part No.
column = New DataGridTextBoxColumn
column.MappingName = "rpn"
column.HeaderText = "Reference Part Number"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Length
column = New DataGridTextBoxColumn
column.MappingName = "l"
column.HeaderText = "Length"
column.Width = 13
tableStyle.GridColumnStyles.Add(column)
' Recommended Spare Part
column = New DataGridTextBoxColumn
column.MappingName = "rsp"
column.HeaderText = "RSP"
column.Width = 7
tableStyle.GridColumnStyles.Add(column)
' Part Description
column = New DataGridTextBoxColumn
column.MappingName = "pdesc"
column.HeaderText = "Part Description"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Manufactured By
column = New DataGridTextBoxColumn
column.MappingName = "mfgby"
column.HeaderText = "Manufactured By"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Revision
column = New DataGridTextBoxColumn
column.MappingName = "rev"
column.HeaderText = "Revision"
column.Width = 7
tableStyle.GridColumnStyles.Add(column)
' Manufacturer Code
column = New DataGridTextBoxColumn
column.MappingName = "mfgcode"
column.HeaderText = "Manufacturer Code"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Material Code
column = New DataGridTextBoxColumn
column.MappingName = "macode"
column.HeaderText = "Material Code"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Material Description
column = New DataGridTextBoxColumn
column.MappingName = "mat"
column.HeaderText = "Material Description"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Part Finish
column = New DataGridTextBoxColumn
column.MappingName = "fin"
column.HeaderText = "Part Finish"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Designer
column = New DataGridTextBoxColumn
column.MappingName = "des"
column.HeaderText = "Designer"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
' Rendered Material / Property
column = New DataGridTextBoxColumn
column.MappingName = "renmatp"
column.HeaderText = "Material Property"
column.Width = 25
tableStyle.GridColumnStyles.Add(column)
tableStyle.MappingName = "MetroParts"
DataGrid1.TableStyles.Add(tableStyle)
' Define Data Table
Dim dt As DataTable = New DataTable
Dim dc As DataColumn
' Add Columns
'Part Number
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "pn"
dc.AutoIncrement = False
dc.Caption = "Part Number"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Reference Part No.
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "rpn"
dc.AutoIncrement = False
dc.Caption = "Reference Part Number"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Length
dc = New DataColumn
dc.DataType = System.Type.GetType("System.Single")
dc.ColumnName = "l"
dc.AutoIncrement = False
dc.Caption = "Length"
dc.ReadOnly = False
dc.Unique = False
' Recommended Spare Part
dc = New DataColumn
dc.DataType = System.Type.GetType("System.Boolean")
dc.ColumnName = "rsp"
dc.AutoIncrement = False
dc.Caption = "Length"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Part Description
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "pdesc"
dc.AutoIncrement = False
dc.Caption = "Part Description"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Manufactured By
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "mfgby"
dc.AutoIncrement = False
dc.Caption = "Manufactured By"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Revision
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "rev"
dc.AutoIncrement = False
dc.Caption = "Revision"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Manufacturer Code
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "mfgcode"
dc.AutoIncrement = False
dc.Caption = "Manufacturer Code"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Material Code
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "macode"
dc.AutoIncrement = False
dc.Caption = "Material Code"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Material
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "mat"
dc.AutoIncrement = False
dc.Caption = "Material"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Finish
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "fin"
dc.AutoIncrement = False
dc.Caption = "Finish"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Designer
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "des"
dc.AutoIncrement = False
dc.Caption = "Designer"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Rendered Material / Property
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "renmatp"
dc.AutoIncrement = False
dc.Caption = "Material Property"
dc.ReadOnly = False
dc.Unique = False
dt.Columns.Add(dc)
' Define Dataset
Dim ds As New DataSet
ds.Tables.Add(dt)
' Add Rows
Dim dr As DataRow
dr("id") = 0
dr("Item") = 0.ToString(PN, RPN, L, RSP, PDesc, MFGBY, REV, MFGCODE, MACODE, MAT, FIN, DES, RENMATP)
dt.Rows.Add(dr)
DataGrid1.DataSource = dt
DataGrid1.AllowSorting = True
'' Add Columns - simpler methodology worked great!
'dt.Columns.Add("Part Number", GetType(System.String))
'dt.Columns.Add("Reference Part Number", GetType(System.String))
'dt.Columns.Add("Length", GetType(System.Single))
'dt.Columns.Add("RSP", GetType(System.Boolean))
'dt.Columns.Add("Part Description", GetType(System.String))
'dt.Columns.Add("Manufactured By", GetType(System.String))
'dt.Columns.Add("Revision", GetType(System.String))
'dt.Columns.Add("Manufacturer Code", GetType(System.String))
'dt.Columns.Add("Material Code", GetType(System.String))
'dt.Columns.Add("Material Description", GetType(System.String))
'dt.Columns.Add("Part Finish", GetType(System.String))
'dt.Columns.Add("Designer", GetType(System.String))
'dt.Columns.Add("Material Property", GetType(System.String))
'' Add Rows
'dt.Rows.Add(New String() {PN, RPN, L, RSP, PDesc, MFGBY, REV, MFGCODE, MACODE, MAT, FIN, DES, RENMATP})
'' Update Data to DataGrid1
'DataGrid1.DataSource = dt
'DataGrid1.AllowSorting = True
End Sub