472,352 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 software developers and data experts.

little help with datagrid

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
14 1727
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
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
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create:...
9
by: Eric S. | last post by:
Why doesn't something like this work? I get "a constant value is expected" on all 3 case statements. private DataGrid CurrentDataGrid(DataGrid...
2
by: Richard | last post by:
DataGrid Row Second Row Selected. How do I not show that blank row with the > abc abc abc abc > abc abc abc abc abc abc abc abc abc abc abc...
6
by: Andreas Klemt | last post by:
Hello, I have this Public Structure strucUser Dim userIDAs Integer Dim firstnameAs String Dim lastname As String End Structure Dim...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms...
2
by: Nina | last post by:
Hi there, I've tried everything that I know to prevent usre resizing datagrid columns, but nothing works. Following are the code that I used. ...
1
by: Coleen | last post by:
To export data from a datagrid to an excel file. I am using VB.net/ASP.net v 2003, and not connecting to an SQL database. I have an existing...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.