WoundEdGoat
Programmer
Right, well I've been searching around the net for about half a day now and to be quite honest, I'm under the impression that my conception of how to use a DataGrid control is horribly flawed (or non-existent).
What I would like to do is pass the data in a Collection (containing objects from a class I wrote) to a DataGrid control so that it can be easily viewed and possibly sorted.
I've got it to display the data with the DataGrid.DataSource = Collection line, but it displays the data columns in an order I've not yet figured out how it came by. After doing some more research on the net, I learned of the TableStyles and GridColumnStyles collections. Well, I tried to implement these into my code, both using the properties window and via code, but they don't seem to work, leading me to believe that I haven't a clue to what I'm doing.
I suppose what I'm here to ask is for some direction as to what I'm suppose to do to get this thing to work properly. I'll post a cut down version of my code below.
My Class (Basically):
And the TableStyles and GridColumnStyles code (which I copied off a website and modified to fit my program... Or at least that was the idea), which is in my Form.Load event currently:
After this, I'm stumped. It didn't make a difference if I put the DataGrid.DataSource = Collection either before or after the latter block of code. Any help would be greatly appreciated. Thanks.
What I would like to do is pass the data in a Collection (containing objects from a class I wrote) to a DataGrid control so that it can be easily viewed and possibly sorted.
I've got it to display the data with the DataGrid.DataSource = Collection line, but it displays the data columns in an order I've not yet figured out how it came by. After doing some more research on the net, I learned of the TableStyles and GridColumnStyles collections. Well, I tried to implement these into my code, both using the properties window and via code, but they don't seem to work, leading me to believe that I haven't a clue to what I'm doing.
I suppose what I'm here to ask is for some direction as to what I'm suppose to do to get this thing to work properly. I'll post a cut down version of my code below.
My Class (Basically):
Code:
Public Class DataClass
Private strString as String
Private intNumber as Integer
Public Property StringProp() As String
Get
Return strString
End Get
Set(ByVal Value As String)
strString = Value
End Set
End Property
Public Property NumberProp() As Integer
Get
Return intNumber
End Get
Set(ByVal Value As Integer)
intNumber = Value
End Set
End Property
Public Sub New()
' Code
End Sub
End Class
And the TableStyles and GridColumnStyles code (which I copied off a website and modified to fit my program... Or at least that was the idea), which is in my Form.Load event currently:
Code:
Dim dgtsTable As New DataGridTableStyle()
dgtsTable.MappingName = "DataClass” ' Not sure if this is correct...
Dim dgtbString As New DataGridTextBoxColumn()
dgtbString.HeaderText = "String Value"
dgtbString.MappingName = "StringProp" ' Or if this is correct...
dgtbString.Width = "165"
dgtsTable.GridColumnStyles.Add(dgtbString)
Dim dgtbNumber As New DataGridTextBoxColumn()
dgtbNumber.HeaderText = "Number Value"
dgtbNumber.MappingName = "NumberProp" ' Or this...
dgtbNumber.Width = "180"
dgtsTable.GridColumnStyles.Add(dgtbNumber)
dgdDataGrid.TableStyles.Clear()
dgdDataGrid.TableStyles.Add(dgtsTable)
After this, I'm stumped. It didn't make a difference if I put the DataGrid.DataSource = Collection either before or after the latter block of code. Any help would be greatly appreciated. Thanks.