I bind a collection to a data grid, and it works okay, but when I try to
create customized columns, it just doesn't work. Here is the code. Note
that if I uncomment that section below, and use "DT" as the mapping
name, it works fine. But I don't want to have to copy the collection to
the data table every time.
I searched Google and keep reading that you have to use "the classname
of the collection," but nothing I use as a mapping name gives me any
results. I just get a blank datagrid. Thanks for any suggestions.
=== code
Module x
Global objElecMotor as clsElecMotor
Global ElecMotors As New Collection()
End Module
Public Class frmList
Inherits System.Windows.Forms.Form
Private Sub frmList_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim Column1 As New DataGridTextBoxColumn()
Column1.MappingName = "MotorID"
Column1.HeaderText = "ID"
Column1.Width = 40
Dim Column2 As New DataGridTextBoxColumn()
Column2.MappingName = "Description"
Column2.HeaderText = "Desc"
Column2.Width = 100
Dim Column3 As New DataGridTextBoxColumn()
Column3.MappingName = "RPM"
Column3.HeaderText = "RPM"
Column3.Width = 40
Dim Column4 As New DataGridTextBoxColumn()
Column4.MappingName = "Voltage"
Column4.HeaderText = "Volts"
Column4.Width = 30
Dim Column5 As New DataGridTextBoxColumn()
Column5.MappingName = "Status"
Column5.HeaderText = "STS"
Column5.Width = 40
Dim NewStyle As New DataGridTableStyle()
NewStyle.MappingName = "?????????????"
NewStyle.GridColumnStyles.Add(Column1)
NewStyle.GridColumnStyles.Add(Column2)
NewStyle.GridColumnStyles.Add(Column3)
NewStyle.GridColumnStyles.Add(Column4)
NewStyle.GridColumnStyles.Add(Column5)
'Dim dt As New DataTable("DT")
'dt.Columns.Add("MotorID", Type.GetType("System.String"))
'dt.Columns.Add("Description", Type.GetType("System.String"))
'dt.Columns.Add("RPM", Type.GetType("System.Int32"))
'dt.Columns.Add("Voltage", Type.GetType("System.Int32"))
'dt.Columns.Add("Status", Type.GetType("System.String"))
'Dim obj As clsElecMotor
'For Each obj In ElecMotors
' dt.Rows.Add(New Object() {obj.MotorID, obj.Description, _
obj.RPM, obj.Voltage, obj.Status})
'Next
'DataGrid.DataSource = dt
DataGrid.TableStyles.Clear()
DataGrid.TableStyles.Add(NewStyle)
End Sub