B
Brett Sinclair
Hello everybody
I'm still on the learning curve here...and from what I read, I created
inherited datagrid class so I could have icons, combobox...etc in the
columns of my datagrid.
The grid will be used to populate information coming from a Webservice. (No
datasets - No datareaders).
So, I do not know see how to use the "datasource".
Now I'm almost there...but I would need a little bit of help to
programatically populate the datagrid.
Here is , (I hope) a short code that I use. I create a grid with 3 columns.
the column 1 is a column with text + icon called DataGridIconTextColumn
inherited from the class of the same name.
the column 2 is a column with icon called DataGridIconOnlyColumn inherited
from the class of the same name. Depending on some "flag" I will be using 1
icon or another.
The column 3 is a regular DataGridTextBoxColumn
'load some icons from embedded resources
Me.Icons = New ImageList
Dim iconName As String
iconName = "datagridicons.user.ico"
Dim strm As System.IO.Stream
strm = Me.GetType.Assembly.GetManifestResourceStream(iconName)
Dim icon As Icon
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser1.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(iconName)
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser2.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(iconName)
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
Dim tableStyle As DataGridTableStyle
tableStyle = New DataGridTableStyle
tableStyle.MappingName = "customers"
Dim numCols As Integer
numCols = 3
Dim iconColumn As DataGridIconTextColumn
iconColumn = New DataGridIconTextColumn(Me.Icons, New
delegateGetIconIndexForRow(AddressOf MyGetImageIndexForRow))
iconColumn.HeaderText = "headercolumn1"
iconColumn.MappingName = "headercolumn2"
tableStyle.GridColumnStyles.Add(iconColumn)
Dim iconColumn2 As DataGridIconOnlyColumn
iconColumn2 = New DataGridIconOnlyColumn(Me.Icons, New
delegateGetIconIndexForRow(AddressOf MyGetImageIndexForRow))
iconColumn2.HeaderText = ""
iconColumn2.MappingName = "Icon"
iconColumn2.Width = Me.Icons.Images(0).Size.Width
tableStyle.GridColumnStyles.Add(iconColumn)
Dim aColumnTextColumn As DataGridTextBoxColumn
aColumnTextColumn = New DataGridTextBoxColumn
aColumnTextColumn.HeaderText = "headercolumn3"
aColumnTextColumn.MappingName = "headercolumn3"
tableStyle.GridColumnStyles.Add(aColumnTextColumn)
' make the dataGrid use our new tablestyle and bind it to our
table
dataGrid1.TableStyles.Clear()
dataGrid1.TableStyles.Add(tableStyle)
Now, using a loop (for instance for i = 0 to 5 ...etc), can somebody show me
how to populate the grid ?
Thank you very much in advance
I'm still on the learning curve here...and from what I read, I created
inherited datagrid class so I could have icons, combobox...etc in the
columns of my datagrid.
The grid will be used to populate information coming from a Webservice. (No
datasets - No datareaders).
So, I do not know see how to use the "datasource".
Now I'm almost there...but I would need a little bit of help to
programatically populate the datagrid.
Here is , (I hope) a short code that I use. I create a grid with 3 columns.
the column 1 is a column with text + icon called DataGridIconTextColumn
inherited from the class of the same name.
the column 2 is a column with icon called DataGridIconOnlyColumn inherited
from the class of the same name. Depending on some "flag" I will be using 1
icon or another.
The column 3 is a regular DataGridTextBoxColumn
'load some icons from embedded resources
Me.Icons = New ImageList
Dim iconName As String
iconName = "datagridicons.user.ico"
Dim strm As System.IO.Stream
strm = Me.GetType.Assembly.GetManifestResourceStream(iconName)
Dim icon As Icon
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser1.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(iconName)
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser2.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(iconName)
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
Dim tableStyle As DataGridTableStyle
tableStyle = New DataGridTableStyle
tableStyle.MappingName = "customers"
Dim numCols As Integer
numCols = 3
Dim iconColumn As DataGridIconTextColumn
iconColumn = New DataGridIconTextColumn(Me.Icons, New
delegateGetIconIndexForRow(AddressOf MyGetImageIndexForRow))
iconColumn.HeaderText = "headercolumn1"
iconColumn.MappingName = "headercolumn2"
tableStyle.GridColumnStyles.Add(iconColumn)
Dim iconColumn2 As DataGridIconOnlyColumn
iconColumn2 = New DataGridIconOnlyColumn(Me.Icons, New
delegateGetIconIndexForRow(AddressOf MyGetImageIndexForRow))
iconColumn2.HeaderText = ""
iconColumn2.MappingName = "Icon"
iconColumn2.Width = Me.Icons.Images(0).Size.Width
tableStyle.GridColumnStyles.Add(iconColumn)
Dim aColumnTextColumn As DataGridTextBoxColumn
aColumnTextColumn = New DataGridTextBoxColumn
aColumnTextColumn.HeaderText = "headercolumn3"
aColumnTextColumn.MappingName = "headercolumn3"
tableStyle.GridColumnStyles.Add(aColumnTextColumn)
' make the dataGrid use our new tablestyle and bind it to our
table
dataGrid1.TableStyles.Clear()
dataGrid1.TableStyles.Add(tableStyle)
Now, using a loop (for instance for i = 0 to 5 ...etc), can somebody show me
how to populate the grid ?
Thank you very much in advance