Home All Groups Group Topic Archive Search About

VB.NET Datagrid with pictures

Author
16 Oct 2006 11:28 PM
Matt
Guys I could really use some help with this.  I think that it's
probably a simple solution but I haven't been able to find anything.

I have a datagrid on my form that I populate via code like this...

Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)

Well now I have a datagrid that I want to populate with an image.

So for example...

Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)

How do I do this?

I know I can change the "column type" to an "image" column but how do I
add one with code?

The next best thing would to be able to statically add an image and
make it visible or invisible by row.

Any advice would be appreciated.

Author
17 Oct 2006 3:31 AM
Scott M.
I've done this by placing an image control in a template column of a
DataGrid and then binding the image control's url property to the path of
the image (which is stored in my database along with the other data for that
given record).

Works like a charm.

Show quoteHide quote
"Matt" <Kru***@gmail.com> wrote in message
news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
> Guys I could really use some help with this.  I think that it's
> probably a simple solution but I haven't been able to find anything.
>
> I have a datagrid on my form that I populate via code like this...
>
> Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
>
> Well now I have a datagrid that I want to populate with an image.
>
> So for example...
>
> Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
>
> How do I do this?
>
> I know I can change the "column type" to an "image" column but how do I
> add one with code?
>
> The next best thing would to be able to statically add an image and
> make it visible or invisible by row.
>
> Any advice would be appreciated.
>
Author
17 Oct 2006 1:39 PM
Matt
I'm not sure I understand how to do this scott, could you elaborate a
little bit please?

Thank you :-)


Scott M. wrote:
Show quoteHide quote
> I've done this by placing an image control in a template column of a
> DataGrid and then binding the image control's url property to the path of
> the image (which is stored in my database along with the other data for that
> given record).
>
> Works like a charm.
>
> "Matt" <Kru***@gmail.com> wrote in message
> news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
> > Guys I could really use some help with this.  I think that it's
> > probably a simple solution but I haven't been able to find anything.
> >
> > I have a datagrid on my form that I populate via code like this...
> >
> > Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
> >
> > Well now I have a datagrid that I want to populate with an image.
> >
> > So for example...
> >
> > Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
> >
> > How do I do this?
> >
> > I know I can change the "column type" to an "image" column but how do I
> > add one with code?
> >
> > The next best thing would to be able to statically add an image and
> > make it visible or invisible by row.
> >
> > Any advice would be appreciated.
> >
Author
17 Oct 2006 4:00 PM
Scott M.
You need to add "Template" columns to your DataGrid first....

1.  Right click on your grid and choose "Property Builder"
2.  Select the "Columns" category on the left side
3.  Select a "Bound Column" from the "Available Columns" section
4.  Click the  ">" button to add a bound column to the "Selected Columns"
section
5.  Enter the field name from your data source you want to bind to in the
"DataField" textbox.
     (this should be the name of the field in your database that contains
the image path)
6.  Now, click the hyperlink at the bottom of the window that says "Convert
this column into a Template column"
7.  Type what you want this column to have as header text in the "Header
Text" textbox
8.  Click OK
9.  Right click on your grid and choose "Edit Template" and when the sub
menu appears choose the new column you just added.
10.  There will already be a label control in the "Item Template" section of
the screen you see.  Select it and look at its "DataBindings" property
(you'll need to click the "..." button to get there.
11.  Select the whole "Custom Binding Exression" text & click "Cancel"
12.  Now, delete the label control and replace it with an Image control.
13.  Go into the DataBindings property and paste in the same text you just
copied out of the label.

Assuming the rest of your DataGrid's code is set up to bind to its data
source, you should now have an image in your grid.
Show quoteHide quote
"Matt" <Kru***@gmail.com> wrote in message
news:1161092367.065916.265370@i3g2000cwc.googlegroups.com...
> I'm not sure I understand how to do this scott, could you elaborate a
> little bit please?
>
> Thank you :-)
>
>
> Scott M. wrote:
>> I've done this by placing an image control in a template column of a
>> DataGrid and then binding the image control's url property to the path of
>> the image (which is stored in my database along with the other data for
>> that
>> given record).
>>
>> Works like a charm.
>>
>> "Matt" <Kru***@gmail.com> wrote in message
>> news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
>> > Guys I could really use some help with this.  I think that it's
>> > probably a simple solution but I haven't been able to find anything.
>> >
>> > I have a datagrid on my form that I populate via code like this...
>> >
>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
>> >
>> > Well now I have a datagrid that I want to populate with an image.
>> >
>> > So for example...
>> >
>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
>> >
>> > How do I do this?
>> >
>> > I know I can change the "column type" to an "image" column but how do I
>> > add one with code?
>> >
>> > The next best thing would to be able to statically add an image and
>> > make it visible or invisible by row.
>> >
>> > Any advice would be appreciated.
>> >
>
Author
17 Oct 2006 4:22 PM
Miro
Thank you scott,

I was reading the posts and I seen this one and wondered how to do this.

I would have also had to ask this about a month later.
Thank you for the step by step example.

Miro

Show quoteHide quote
"Scott M." <s-mar@nospam.nospam> wrote in message
news:%235KKYVg8GHA.2364@TK2MSFTNGP02.phx.gbl...
> You need to add "Template" columns to your DataGrid first....
>
> 1.  Right click on your grid and choose "Property Builder"
> 2.  Select the "Columns" category on the left side
> 3.  Select a "Bound Column" from the "Available Columns" section
> 4.  Click the  ">" button to add a bound column to the "Selected Columns"
> section
> 5.  Enter the field name from your data source you want to bind to in the
> "DataField" textbox.
>     (this should be the name of the field in your database that contains
> the image path)
> 6.  Now, click the hyperlink at the bottom of the window that says
> "Convert this column into a Template column"
> 7.  Type what you want this column to have as header text in the "Header
> Text" textbox
> 8.  Click OK
> 9.  Right click on your grid and choose "Edit Template" and when the sub
> menu appears choose the new column you just added.
> 10.  There will already be a label control in the "Item Template" section
> of the screen you see.  Select it and look at its "DataBindings" property
> (you'll need to click the "..." button to get there.
> 11.  Select the whole "Custom Binding Exression" text & click "Cancel"
> 12.  Now, delete the label control and replace it with an Image control.
> 13.  Go into the DataBindings property and paste in the same text you just
> copied out of the label.
>
> Assuming the rest of your DataGrid's code is set up to bind to its data
> source, you should now have an image in your grid.
> "Matt" <Kru***@gmail.com> wrote in message
> news:1161092367.065916.265370@i3g2000cwc.googlegroups.com...
>> I'm not sure I understand how to do this scott, could you elaborate a
>> little bit please?
>>
>> Thank you :-)
>>
>>
>> Scott M. wrote:
>>> I've done this by placing an image control in a template column of a
>>> DataGrid and then binding the image control's url property to the path
>>> of
>>> the image (which is stored in my database along with the other data for
>>> that
>>> given record).
>>>
>>> Works like a charm.
>>>
>>> "Matt" <Kru***@gmail.com> wrote in message
>>> news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
>>> > Guys I could really use some help with this.  I think that it's
>>> > probably a simple solution but I haven't been able to find anything.
>>> >
>>> > I have a datagrid on my form that I populate via code like this...
>>> >
>>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
>>> >
>>> > Well now I have a datagrid that I want to populate with an image.
>>> >
>>> > So for example...
>>> >
>>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
>>> >
>>> > How do I do this?
>>> >
>>> > I know I can change the "column type" to an "image" column but how do
>>> > I
>>> > add one with code?
>>> >
>>> > The next best thing would to be able to statically add an image and
>>> > make it visible or invisible by row.
>>> >
>>> > Any advice would be appreciated.
>>> >
>>
>
>
Author
17 Oct 2006 7:53 PM
Scott M.
Oops!  Add this:

11a:  Copy the selected text to the clipboard



Show quoteHide quote
"Scott M." <s-mar@nospam.nospam> wrote in message
news:%235KKYVg8GHA.2364@TK2MSFTNGP02.phx.gbl...
> You need to add "Template" columns to your DataGrid first....
>
> 1.  Right click on your grid and choose "Property Builder"
> 2.  Select the "Columns" category on the left side
> 3.  Select a "Bound Column" from the "Available Columns" section
> 4.  Click the  ">" button to add a bound column to the "Selected Columns"
> section
> 5.  Enter the field name from your data source you want to bind to in the
> "DataField" textbox.
>     (this should be the name of the field in your database that contains
> the image path)
> 6.  Now, click the hyperlink at the bottom of the window that says
> "Convert this column into a Template column"
> 7.  Type what you want this column to have as header text in the "Header
> Text" textbox
> 8.  Click OK
> 9.  Right click on your grid and choose "Edit Template" and when the sub
> menu appears choose the new column you just added.
> 10.  There will already be a label control in the "Item Template" section
> of the screen you see.  Select it and look at its "DataBindings" property
> (you'll need to click the "..." button to get there.
> 11.  Select the whole "Custom Binding Exression" text & click "Cancel"
> 12.  Now, delete the label control and replace it with an Image control.
> 13.  Go into the DataBindings property and paste in the same text you just
> copied out of the label.
>
> Assuming the rest of your DataGrid's code is set up to bind to its data
> source, you should now have an image in your grid.
> "Matt" <Kru***@gmail.com> wrote in message
> news:1161092367.065916.265370@i3g2000cwc.googlegroups.com...
>> I'm not sure I understand how to do this scott, could you elaborate a
>> little bit please?
>>
>> Thank you :-)
>>
>>
>> Scott M. wrote:
>>> I've done this by placing an image control in a template column of a
>>> DataGrid and then binding the image control's url property to the path
>>> of
>>> the image (which is stored in my database along with the other data for
>>> that
>>> given record).
>>>
>>> Works like a charm.
>>>
>>> "Matt" <Kru***@gmail.com> wrote in message
>>> news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
>>> > Guys I could really use some help with this.  I think that it's
>>> > probably a simple solution but I haven't been able to find anything.
>>> >
>>> > I have a datagrid on my form that I populate via code like this...
>>> >
>>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
>>> >
>>> > Well now I have a datagrid that I want to populate with an image.
>>> >
>>> > So for example...
>>> >
>>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
>>> >
>>> > How do I do this?
>>> >
>>> > I know I can change the "column type" to an "image" column but how do
>>> > I
>>> > add one with code?
>>> >
>>> > The next best thing would to be able to statically add an image and
>>> > make it visible or invisible by row.
>>> >
>>> > Any advice would be appreciated.
>>> >
>>
>
>
Author
17 Oct 2006 9:40 PM
Matt
Scott,

Although I truly appreciate the effort I believe that your instructions
are refering to a datagrid in ASP.NET, the type that I'm refering to is
for VB.NET on a form.


Scott M. wrote:
Show quoteHide quote
> Oops!  Add this:
>
> 11a:  Copy the selected text to the clipboard
>
>
>
> "Scott M." <s-mar@nospam.nospam> wrote in message
> news:%235KKYVg8GHA.2364@TK2MSFTNGP02.phx.gbl...
> > You need to add "Template" columns to your DataGrid first....
> >
> > 1.  Right click on your grid and choose "Property Builder"
> > 2.  Select the "Columns" category on the left side
> > 3.  Select a "Bound Column" from the "Available Columns" section
> > 4.  Click the  ">" button to add a bound column to the "Selected Columns"
> > section
> > 5.  Enter the field name from your data source you want to bind to in the
> > "DataField" textbox.
> >     (this should be the name of the field in your database that contains
> > the image path)
> > 6.  Now, click the hyperlink at the bottom of the window that says
> > "Convert this column into a Template column"
> > 7.  Type what you want this column to have as header text in the "Header
> > Text" textbox
> > 8.  Click OK
> > 9.  Right click on your grid and choose "Edit Template" and when the sub
> > menu appears choose the new column you just added.
> > 10.  There will already be a label control in the "Item Template" section
> > of the screen you see.  Select it and look at its "DataBindings" property
> > (you'll need to click the "..." button to get there.
> > 11.  Select the whole "Custom Binding Exression" text & click "Cancel"
> > 12.  Now, delete the label control and replace it with an Image control.
> > 13.  Go into the DataBindings property and paste in the same text you just
> > copied out of the label.
> >
> > Assuming the rest of your DataGrid's code is set up to bind to its data
> > source, you should now have an image in your grid.
> > "Matt" <Kru***@gmail.com> wrote in message
> > news:1161092367.065916.265370@i3g2000cwc.googlegroups.com...
> >> I'm not sure I understand how to do this scott, could you elaborate a
> >> little bit please?
> >>
> >> Thank you :-)
> >>
> >>
> >> Scott M. wrote:
> >>> I've done this by placing an image control in a template column of a
> >>> DataGrid and then binding the image control's url property to the path
> >>> of
> >>> the image (which is stored in my database along with the other data for
> >>> that
> >>> given record).
> >>>
> >>> Works like a charm.
> >>>
> >>> "Matt" <Kru***@gmail.com> wrote in message
> >>> news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
> >>> > Guys I could really use some help with this.  I think that it's
> >>> > probably a simple solution but I haven't been able to find anything.
> >>> >
> >>> > I have a datagrid on my form that I populate via code like this...
> >>> >
> >>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
> >>> >
> >>> > Well now I have a datagrid that I want to populate with an image.
> >>> >
> >>> > So for example...
> >>> >
> >>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
> >>> >
> >>> > How do I do this?
> >>> >
> >>> > I know I can change the "column type" to an "image" column but how do
> >>> > I
> >>> > add one with code?
> >>> >
> >>> > The next best thing would to be able to statically add an image and
> >>> > make it visible or invisible by row.
> >>> >
> >>> > Any advice would be appreciated.
> >>> >
> >>
> >
> >
Author
17 Oct 2006 11:20 PM
Scott M.
Yes, you are right Matt.  Sorry, I didn't realize you wanted a Windows Forms
answer.  Honestly, I don't do much work in WinForms, so I really can't offer
a suggestion on this.

Sorry!

Good luck.

Show quoteHide quote
"Matt" <Kru***@gmail.com> wrote in message
news:1161121225.420485.25630@h48g2000cwc.googlegroups.com...
> Scott,
>
> Although I truly appreciate the effort I believe that your instructions
> are refering to a datagrid in ASP.NET, the type that I'm refering to is
> for VB.NET on a form.
>
>
> Scott M. wrote:
>> Oops!  Add this:
>>
>> 11a:  Copy the selected text to the clipboard
>>
>>
>>
>> "Scott M." <s-mar@nospam.nospam> wrote in message
>> news:%235KKYVg8GHA.2364@TK2MSFTNGP02.phx.gbl...
>> > You need to add "Template" columns to your DataGrid first....
>> >
>> > 1.  Right click on your grid and choose "Property Builder"
>> > 2.  Select the "Columns" category on the left side
>> > 3.  Select a "Bound Column" from the "Available Columns" section
>> > 4.  Click the  ">" button to add a bound column to the "Selected
>> > Columns"
>> > section
>> > 5.  Enter the field name from your data source you want to bind to in
>> > the
>> > "DataField" textbox.
>> >     (this should be the name of the field in your database that
>> > contains
>> > the image path)
>> > 6.  Now, click the hyperlink at the bottom of the window that says
>> > "Convert this column into a Template column"
>> > 7.  Type what you want this column to have as header text in the
>> > "Header
>> > Text" textbox
>> > 8.  Click OK
>> > 9.  Right click on your grid and choose "Edit Template" and when the
>> > sub
>> > menu appears choose the new column you just added.
>> > 10.  There will already be a label control in the "Item Template"
>> > section
>> > of the screen you see.  Select it and look at its "DataBindings"
>> > property
>> > (you'll need to click the "..." button to get there.
>> > 11.  Select the whole "Custom Binding Exression" text & click "Cancel"
>> > 12.  Now, delete the label control and replace it with an Image
>> > control.
>> > 13.  Go into the DataBindings property and paste in the same text you
>> > just
>> > copied out of the label.
>> >
>> > Assuming the rest of your DataGrid's code is set up to bind to its data
>> > source, you should now have an image in your grid.
>> > "Matt" <Kru***@gmail.com> wrote in message
>> > news:1161092367.065916.265370@i3g2000cwc.googlegroups.com...
>> >> I'm not sure I understand how to do this scott, could you elaborate a
>> >> little bit please?
>> >>
>> >> Thank you :-)
>> >>
>> >>
>> >> Scott M. wrote:
>> >>> I've done this by placing an image control in a template column of a
>> >>> DataGrid and then binding the image control's url property to the
>> >>> path
>> >>> of
>> >>> the image (which is stored in my database along with the other data
>> >>> for
>> >>> that
>> >>> given record).
>> >>>
>> >>> Works like a charm.
>> >>>
>> >>> "Matt" <Kru***@gmail.com> wrote in message
>> >>> news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
>> >>> > Guys I could really use some help with this.  I think that it's
>> >>> > probably a simple solution but I haven't been able to find
>> >>> > anything.
>> >>> >
>> >>> > I have a datagrid on my form that I populate via code like this...
>> >>> >
>> >>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
>> >>> >
>> >>> > Well now I have a datagrid that I want to populate with an image.
>> >>> >
>> >>> > So for example...
>> >>> >
>> >>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
>> >>> >
>> >>> > How do I do this?
>> >>> >
>> >>> > I know I can change the "column type" to an "image" column but how
>> >>> > do
>> >>> > I
>> >>> > add one with code?
>> >>> >
>> >>> > The next best thing would to be able to statically add an image and
>> >>> > make it visible or invisible by row.
>> >>> >
>> >>> > Any advice would be appreciated.
>> >>> >
>> >>
>> >
>> >
>
Author
18 Oct 2006 3:48 PM
Matt
I actually figured it out last night.  You have to create an Image
object and pass it in like you would a string.

But thanks to everyone for your efforts!

Cheers


Scott M. wrote:
Show quoteHide quote
> Yes, you are right Matt.  Sorry, I didn't realize you wanted a Windows Forms
> answer.  Honestly, I don't do much work in WinForms, so I really can't offer
> a suggestion on this.
>
> Sorry!
>
> Good luck.
>
> "Matt" <Kru***@gmail.com> wrote in message
> news:1161121225.420485.25630@h48g2000cwc.googlegroups.com...
> > Scott,
> >
> > Although I truly appreciate the effort I believe that your instructions
> > are refering to a datagrid in ASP.NET, the type that I'm refering to is
> > for VB.NET on a form.
> >
> >
> > Scott M. wrote:
> >> Oops!  Add this:
> >>
> >> 11a:  Copy the selected text to the clipboard
> >>
> >>
> >>
> >> "Scott M." <s-mar@nospam.nospam> wrote in message
> >> news:%235KKYVg8GHA.2364@TK2MSFTNGP02.phx.gbl...
> >> > You need to add "Template" columns to your DataGrid first....
> >> >
> >> > 1.  Right click on your grid and choose "Property Builder"
> >> > 2.  Select the "Columns" category on the left side
> >> > 3.  Select a "Bound Column" from the "Available Columns" section
> >> > 4.  Click the  ">" button to add a bound column to the "Selected
> >> > Columns"
> >> > section
> >> > 5.  Enter the field name from your data source you want to bind to in
> >> > the
> >> > "DataField" textbox.
> >> >     (this should be the name of the field in your database that
> >> > contains
> >> > the image path)
> >> > 6.  Now, click the hyperlink at the bottom of the window that says
> >> > "Convert this column into a Template column"
> >> > 7.  Type what you want this column to have as header text in the
> >> > "Header
> >> > Text" textbox
> >> > 8.  Click OK
> >> > 9.  Right click on your grid and choose "Edit Template" and when the
> >> > sub
> >> > menu appears choose the new column you just added.
> >> > 10.  There will already be a label control in the "Item Template"
> >> > section
> >> > of the screen you see.  Select it and look at its "DataBindings"
> >> > property
> >> > (you'll need to click the "..." button to get there.
> >> > 11.  Select the whole "Custom Binding Exression" text & click "Cancel"
> >> > 12.  Now, delete the label control and replace it with an Image
> >> > control.
> >> > 13.  Go into the DataBindings property and paste in the same text you
> >> > just
> >> > copied out of the label.
> >> >
> >> > Assuming the rest of your DataGrid's code is set up to bind to its data
> >> > source, you should now have an image in your grid.
> >> > "Matt" <Kru***@gmail.com> wrote in message
> >> > news:1161092367.065916.265370@i3g2000cwc.googlegroups.com...
> >> >> I'm not sure I understand how to do this scott, could you elaborate a
> >> >> little bit please?
> >> >>
> >> >> Thank you :-)
> >> >>
> >> >>
> >> >> Scott M. wrote:
> >> >>> I've done this by placing an image control in a template column of a
> >> >>> DataGrid and then binding the image control's url property to the
> >> >>> path
> >> >>> of
> >> >>> the image (which is stored in my database along with the other data
> >> >>> for
> >> >>> that
> >> >>> given record).
> >> >>>
> >> >>> Works like a charm.
> >> >>>
> >> >>> "Matt" <Kru***@gmail.com> wrote in message
> >> >>> news:1161041303.204588.240780@f16g2000cwb.googlegroups.com...
> >> >>> > Guys I could really use some help with this.  I think that it's
> >> >>> > probably a simple solution but I haven't been able to find
> >> >>> > anything.
> >> >>> >
> >> >>> > I have a datagrid on my form that I populate via code like this...
> >> >>> >
> >> >>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Column3)
> >> >>> >
> >> >>> > Well now I have a datagrid that I want to populate with an image.
> >> >>> >
> >> >>> > So for example...
> >> >>> >
> >> >>> > Me.My_DataGrid.Rows.Add(Column1, Column2, Picture)
> >> >>> >
> >> >>> > How do I do this?
> >> >>> >
> >> >>> > I know I can change the "column type" to an "image" column but how
> >> >>> > do
> >> >>> > I
> >> >>> > add one with code?
> >> >>> >
> >> >>> > The next best thing would to be able to statically add an image and
> >> >>> > make it visible or invisible by row.
> >> >>> >
> >> >>> > Any advice would be appreciated.
> >> >>> >
> >> >>
> >> >
> >> >
> >