Hi,
I have a datagridview where i have place a picturebox control on of first colum cells.
I don’t able to alignment the control in the cell.
The grid dispaly it always on top left.
I try to set alignment property style property:
“dgv.Rows(r)(“usrimage”).Style.Alignment = DataGridViewContentAlignment.MiddleCenter”
but with not success.
See attached image
Any suggestion?
Thanks in advance
PictureBox binding is the same as any other control. Bind “Image” (for binaries: png or jpg from a byte[] – it’s all in the standard ImageConverter that you can also override) or “ImageSource” (for URL’s or theme images). You can also use an image column or put an image on any cell using Style.BackgroundImage or BackgroundImageSource. The image can be stored in the style or you can assign it only when rendering the cell for the browser in CellFormatting.
Hi Ala
I found and downloaded the wonderful DemoBrowser application.
Now I understand how the datarepeater works and my application works fine.
Thank you for your suggestion.
Angelo
Hi Angelo,
Did you give our DemoBrowser application a try?
It contains demos of our control set and also source code examples, and the DataRepeater control demo also features binding a PictureBox.
You can access the Documentation and Source code directly from inside the application, or you can browse/clone the repository.
HTH,
Alaa
thank you Alaa.
I think the best way to do this is to use the datarpeater.
Today I tested this control for the first time.
I followed the documentation and examples.
But I have a problem.
Below what I did.
I placed a data repeater (dtrp), label (lbl) and picturebox control (pcbleft).
I defined a class:
Private class clsdtrp
Public Property img As Image
Public Property usr As String
End Class
and finally, in a method I put the code:
Dim itmlist As New BindingList(Of clsdtrp)
For r = 0 To 10
Dim itm As New clsdtrp
itm.img = My.Resources.Leo_01_32
itm.usr = “user” + r.ToString
itmlist.Add(itm)
Next
pcbLeft.DataBindings.Add(“image”, itmlist, “img”, True)
lbl.DataBindings.Add(“Text”, itmlist, “usr”)
dtrp.DataSource = itmlist
Now my problem..
The datarepeater works fine if I just bind the label control.
When I also bind the image box, the datarepater doesn’t show any elements.
I think the problem is in the picturabox binding. I haven’t found any examples (on documentation and examples) of using picturebox el datarepeater .
Any suggestions?
Hi Angelo,
The alignment property is for the content of the cell, not the control inside it.
Any control in a cell can be docked, so you can set its DockStyle to Fill.
In general, the best approach is to place an image in a cell by using the DataGridViewCell.Style.BackgroundImage properties.
HTH,
Alaa
Please login first to submit.