473,473 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1817
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 the row when a user clicks anywhere on a cell...
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: ------------------------------------ A form split into two parts. There is a...
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 firstDg, DataGrid secondDg) { try { switch...
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 abc abc abc abc abc xx yyyyyyyyyyyyyy
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 collectUser As New Collection
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 controls vs. regular HTML. For example in ASP...
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. Please tell me what's wrong with them. Thank you....
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 datagrid that I want to get the data from and download...
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 datagrid. Everything is working fine until I click...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.