By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

little help with datagrid

P: n/a
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(icon Name)
Dim icon As Icon
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser1.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name)
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser2.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name)
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
Nov 20 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Hi,

Brett what format is the data coming from the webservice in? You
can bind a datagrid to an collection or arraylist.

Ken
--------------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
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(icon Name)
Dim icon As Icon
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser1.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name)
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser2.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name)
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

Nov 20 '05 #2

P: n/a
Ken,
There will be several "complex" format received.
The most common case will be an array list, which will be composed itself of
columns strings, enum types, date or subarrays.

But for each line, I will display different icons based on the result
received.

Thanks for your help.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hi,

Brett what format is the data coming from the webservice in? You
can bind a datagrid to an collection or arraylist.

Ken
--------------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
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(icon Name) Dim icon As Icon
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser1.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name) icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser2.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name) 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


Nov 20 '05 #3

P: n/a
Hi Brett,

The datagrid looks when you go deeper in it almost special made for the
dataset
The webservice is completly optimized around using the XML dataset

Is there a special reason that you do not want to use the dataset?

It is just a container to hold tables.

Cor
Nov 20 '05 #4

P: n/a
Hi Cor,
yes. There is a reason. The webservice doesn't return a dataset.
It returns arrays of strings, or user type defined , or dates etc. Depending
on which one are called.

Depending on the records received, I need to display some icons on each
line. I also, need to "transform" certain user type defined field, to become
readable to the user.
A simple example is, the webservice send what supposed to be a date field in
the grid as "PS2004-15-01T04:56:42-8:00". So I would need to transform that.

Maybe there is a way to put the results of the web service into a dataset,
then just set the datasource of the datagrid to it ?

Thank you for you help again.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OB**************@TK2MSFTNGP09.phx.gbl...
Hi Brett,

The datagrid looks when you go deeper in it almost special made for the
dataset
The webservice is completly optimized around using the XML dataset

Is there a special reason that you do not want to use the dataset?

It is just a container to hold tables.

Cor

Nov 20 '05 #5

P: n/a
Hi Brett,

A dataset is so easy to create here a sample I used today.

Maybe you can do something with it.

However if you have more questions feel free to ask.

Cor

\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Dim dc As New DataColumn("OHM")
dc.DataType = GetType(System.Int32)
Dim dd As New DataColumn("OHH")
dd.DataType = GetType(System.String)
dt.Columns.Add(dc)
dt.Columns.Add(dd)
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
dt.Rows(i)(0) = 100
dt.Rows(i)(1) = "1"
Next
Dim ds As New DataSet
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables(0)
End Sub
///
Nov 20 '05 #6

P: n/a
Hi Cor
I tried that solution. it works. But then I could find how to display an
icon in one the columns based on hte value for each rows.
Based on your example, how would you create a 3rd column that just display
an icon ?

Thank you again for your time.
I really appreciate it.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
Hi Brett,

A dataset is so easy to create here a sample I used today.

Maybe you can do something with it.

However if you have more questions feel free to ask.

Cor

\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Dim dc As New DataColumn("OHM")
dc.DataType = GetType(System.Int32)
Dim dd As New DataColumn("OHH")
dd.DataType = GetType(System.String)
dt.Columns.Add(dc)
dt.Columns.Add(dd)
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
dt.Rows(i)(0) = 100
dt.Rows(i)(1) = "1"
Next
Dim ds As New DataSet
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables(0)
End Sub
///

Nov 20 '05 #7

P: n/a
Here is an example that might help.

In the aspx page:

<asp:DataGrid ID="TheGrid" AutoGenerateColumns=False Runat=server>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image ImageUrl=<%# GetImageUrl(Container.DataItem) %>
Runat=server></asp:Image>
<%# GetText(Container.DataItem) %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

In the code behind:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim TheArray As ArrayList = New ArrayList
TheArray.Add(Today())
TheArray.Add("SomeString")
TheArray.Add(23)
TheGrid.DataSource = TheArray
TheGrid.DataBind()
End Sub

Protected Function GetImageUrl(ByVal InDataItem As Object) As String
If TypeOf InDataItem Is Date Then
Return "Date.gif"
ElseIf TypeOf InDataItem Is Integer Then
Return "Integer.gif"
ElseIf TypeOf InDataItem Is String Then
Return "String.gif"
Else
Return "Unknown.gif"
End If
End Function

Protected Function GetText(ByVal InDataItem As Object) As String
If TypeOf InDataItem Is Date Then
Return "Date"
ElseIf TypeOf InDataItem Is Integer Then
Return "Integer"
ElseIf TypeOf InDataItem Is String Then
Return "String"
Else
Return "Unknown"
End If
End Function

"Brett Sinclair" <lb*@nospam.com> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Ken,
There will be several "complex" format received.
The most common case will be an array list, which will be composed itself of columns strings, enum types, date or subarrays.

But for each line, I will display different icons based on the result
received.

Thanks for your help.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hi,

Brett what format is the data coming from the webservice in? You
can bind a datagrid to an collection or arraylist.

Ken
--------------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
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(icon Name) Dim icon As Icon
icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser1.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name) icon = New Icon(strm)
Me.Icons.Images.Add(icon.ToBitmap)
iconName = "datagridicons.IconUser2.ico"
strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name) 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



Nov 20 '05 #8

P: n/a
Sorry - my previous answer is not very clear I think....

Hi Cor
I tried that solution at the beginning. It worked fine. But then I could not
find how to display an
icon in one the columns based on hte value for each rows.
That is why, I changed direction, and tried to create an inherited grid,
with an "iconcolumn" type in it. (see code in original post.)

Based on your example, how would you create a 3rd column that just display
an icon ?

Thank you again for your time.
I really appreciate it.

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
Hi Brett,

A dataset is so easy to create here a sample I used today.

Maybe you can do something with it.

However if you have more questions feel free to ask.

Cor

\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Dim dc As New DataColumn("OHM")
dc.DataType = GetType(System.Int32)
Dim dd As New DataColumn("OHH")
dd.DataType = GetType(System.String)
dt.Columns.Add(dc)
dt.Columns.Add(dd)
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
dt.Rows(i)(0) = 100
dt.Rows(i)(1) = "1"
Next
Dim ds As New DataSet
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables(0)
End Sub
///

Nov 20 '05 #9

P: n/a
Hello Jeff
Thank you for your help. I'm not familiar with asp.net, but from what I can
see, is that at design time, you are able to define you column as "Image
ImageUrl".

In vb.net, I think (once again...I'm still learning) that the only type in a
datagrid is a DataGridTextBoxColumn.
I tried to use a datatable, datacolumn and datarow...but I have a same
problem. I can not add an icon to a datacolumn.

That is why I tried to create an inherited datagrid, where a column will
display an icon...but somehow I can not find the syntax now to loop thru the
records to populate that grid once I have defined each columns.

Thank you again for your help.


"Jeff" <no@email.org> wrote in message
news:ui*************@TK2MSFTNGP11.phx.gbl...
Here is an example that might help.

In the aspx page:

<asp:DataGrid ID="TheGrid" AutoGenerateColumns=False Runat=server>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image ImageUrl=<%# GetImageUrl(Container.DataItem) %>
Runat=server></asp:Image>
<%# GetText(Container.DataItem) %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

In the code behind:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim TheArray As ArrayList = New ArrayList
TheArray.Add(Today())
TheArray.Add("SomeString")
TheArray.Add(23)
TheGrid.DataSource = TheArray
TheGrid.DataBind()
End Sub

Protected Function GetImageUrl(ByVal InDataItem As Object) As String
If TypeOf InDataItem Is Date Then
Return "Date.gif"
ElseIf TypeOf InDataItem Is Integer Then
Return "Integer.gif"
ElseIf TypeOf InDataItem Is String Then
Return "String.gif"
Else
Return "Unknown.gif"
End If
End Function

Protected Function GetText(ByVal InDataItem As Object) As String
If TypeOf InDataItem Is Date Then
Return "Date"
ElseIf TypeOf InDataItem Is Integer Then
Return "Integer"
ElseIf TypeOf InDataItem Is String Then
Return "String"
Else
Return "Unknown"
End If
End Function

"Brett Sinclair" <lb*@nospam.com> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Ken,
There will be several "complex" format received.
The most common case will be an array list, which will be composed itself
of
columns strings, enum types, date or subarrays.

But for each line, I will display different icons based on the result
received.

Thanks for your help.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hi,

Brett what format is the data coming from the webservice in?

You can bind a datagrid to an collection or arraylist.

Ken
--------------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
> 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(icon Name)
> Dim icon As Icon
> icon = New Icon(strm)
> Me.Icons.Images.Add(icon.ToBitmap)
> iconName = "datagridicons.IconUser1.ico"
> strm =

Me.GetType.Assembly.GetManifestResourceStream(icon Name)
> icon = New Icon(strm)
> Me.Icons.Images.Add(icon.ToBitmap)
> iconName = "datagridicons.IconUser2.ico"
> strm =

Me.GetType.Assembly.GetManifestResourceStream(icon Name)
> 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
>
>



Nov 20 '05 #10

P: n/a
My bad anyway, I see you are using window and not asp.net. sorry for the
confusion.

"Brett Sinclair" <lb*@nospam.com> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
Hello Jeff
Thank you for your help. I'm not familiar with asp.net, but from what I can see, is that at design time, you are able to define you column as "Image
ImageUrl".

In vb.net, I think (once again...I'm still learning) that the only type in a datagrid is a DataGridTextBoxColumn.
I tried to use a datatable, datacolumn and datarow...but I have a same
problem. I can not add an icon to a datacolumn.

That is why I tried to create an inherited datagrid, where a column will
display an icon...but somehow I can not find the syntax now to loop thru the records to populate that grid once I have defined each columns.

Thank you again for your help.


"Jeff" <no@email.org> wrote in message
news:ui*************@TK2MSFTNGP11.phx.gbl...
Here is an example that might help.

In the aspx page:

<asp:DataGrid ID="TheGrid" AutoGenerateColumns=False Runat=server>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image ImageUrl=<%# GetImageUrl(Container.DataItem) %>
Runat=server></asp:Image>
<%# GetText(Container.DataItem) %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

In the code behind:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim TheArray As ArrayList = New ArrayList
TheArray.Add(Today())
TheArray.Add("SomeString")
TheArray.Add(23)
TheGrid.DataSource = TheArray
TheGrid.DataBind()
End Sub

Protected Function GetImageUrl(ByVal InDataItem As Object) As String
If TypeOf InDataItem Is Date Then
Return "Date.gif"
ElseIf TypeOf InDataItem Is Integer Then
Return "Integer.gif"
ElseIf TypeOf InDataItem Is String Then
Return "String.gif"
Else
Return "Unknown.gif"
End If
End Function

Protected Function GetText(ByVal InDataItem As Object) As String
If TypeOf InDataItem Is Date Then
Return "Date"
ElseIf TypeOf InDataItem Is Integer Then
Return "Integer"
ElseIf TypeOf InDataItem Is String Then
Return "String"
Else
Return "Unknown"
End If
End Function

"Brett Sinclair" <lb*@nospam.com> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Ken,
There will be several "complex" format received.
The most common case will be an array list, which will be composed itself
of
columns strings, enum types, date or subarrays.

But for each line, I will display different icons based on the result
received.

Thanks for your help.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> Brett what format is the data coming from the webservice in?

You
> can bind a datagrid to an collection or arraylist.
>
> Ken
> --------------------
> "Brett Sinclair" <lb*@nospam.com> wrote in message
> news:e9*************@tk2msftngp13.phx.gbl...
> > 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(icon Name)
> > Dim icon As Icon
> > icon = New Icon(strm)
> > Me.Icons.Images.Add(icon.ToBitmap)
> > iconName = "datagridicons.IconUser1.ico"
> > strm =
Me.GetType.Assembly.GetManifestResourceStream(icon Name)
> > icon = New Icon(strm)
> > Me.Icons.Images.Add(icon.ToBitmap)
> > iconName = "datagridicons.IconUser2.ico"
> > strm =
Me.GetType.Assembly.GetManifestResourceStream(icon Name)
> > 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
> >
> >
>
>



Nov 20 '05 #11

P: n/a
Hi Brett,

A datagrid has only two standard columns the textbox column and the bool
column.

I inherited some other controls in the columns myself however never an icon
column and I have now and tomorrow not the time to try to make it for you,
however that should not be a problem for you.

Jan Tielemans a time a regular in this newsgroup has made a complete
datagrid with icons in it and I thought that I had heard it was working
good..

It is free
http://dotnet.leadit.be/extendeddatagrid

Maybe you can try that.

Cor
Nov 20 '05 #12

P: n/a
Hi,

In addition to the other comments. Here is a link to the extended
grid. It is a open source datagrid that adds image columns.

http://dotnet.leadit.be/extendeddata...?category=Home

Ken
-----------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Ken,
There will be several "complex" format received.
The most common case will be an array list, which will be composed itself
of
columns strings, enum types, date or subarrays.

But for each line, I will display different icons based on the result
received.

Thanks for your help.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hi,

Brett what format is the data coming from the webservice in? You
can bind a datagrid to an collection or arraylist.

Ken
--------------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
> 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(icon Name) > Dim icon As Icon
> icon = New Icon(strm)
> Me.Icons.Images.Add(icon.ToBitmap)
> iconName = "datagridicons.IconUser1.ico"
> strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name) > icon = New Icon(strm)
> Me.Icons.Images.Add(icon.ToBitmap)
> iconName = "datagridicons.IconUser2.ico"
> strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name) > 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
>
>



Nov 20 '05 #13

P: n/a
Cor
Thank you already for all your help, I will try to look into that grid
provided by Jan Tielemans.

In the meantime, if you inherited some other controls...theoretically it
should work the same.
Let's say on column 3 you have a combobox (already loaded then) or a
label...
how do you build your loop ?

Thank you
\
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi Brett,

A datagrid has only two standard columns the textbox column and the bool
column.

I inherited some other controls in the columns myself however never an icon column and I have now and tomorrow not the time to try to make it for you,
however that should not be a problem for you.

Jan Tielemans a time a regular in this newsgroup has made a complete
datagrid with icons in it and I thought that I had heard it was working
good..

It is free
http://dotnet.leadit.be/extendeddatagrid

Maybe you can try that.

Cor

Nov 20 '05 #14

P: n/a
Do you know where I can find vb.net example ?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ud*************@TK2MSFTNGP10.phx.gbl...
Hi,

In addition to the other comments. Here is a link to the extended
grid. It is a open source datagrid that adds image columns.

http://dotnet.leadit.be/extendeddata...?category=Home

Ken
-----------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:uS**************@TK2MSFTNGP09.phx.gbl...
Ken,
There will be several "complex" format received.
The most common case will be an array list, which will be composed itself of
columns strings, enum types, date or subarrays.

But for each line, I will display different icons based on the result
received.

Thanks for your help.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hi,

Brett what format is the data coming from the webservice in? You can bind a datagrid to an collection or arraylist.

Ken
--------------------
"Brett Sinclair" <lb*@nospam.com> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
> 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(icon Name)
> Dim icon As Icon
> icon = New Icon(strm)
> Me.Icons.Images.Add(icon.ToBitmap)
> iconName = "datagridicons.IconUser1.ico"
> strm =

Me.GetType.Assembly.GetManifestResourceStream(icon Name)
> icon = New Icon(strm)
> Me.Icons.Images.Add(icon.ToBitmap)
> iconName = "datagridicons.IconUser2.ico"
> strm =

Me.GetType.Assembly.GetManifestResourceStream(icon Name)
> 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
>
>



Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.