Javier Gonzalez de Aragon
Top achievements
Rank 2
Javier Gonzalez de Aragon
asked on 22 Nov 2012, 01:22 AM
Hi.
I have a Listview control populated using a Datadapter. I want to display an image from an ImageList control. The index is based on a value in a column. How can I achieve this?
Thanks,
Javier
I have a Listview control populated using a Datadapter. I want to display an image from an ImageList control. The index is based on a value in a column. How can I achieve this?
Thanks,
Javier
4 Answers, 1 is accepted
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 23 Nov 2012, 08:07 PM
I have found the way.
Private
Sub
lvLista_CellFormatting(sender
As
Object
, e
As
Telerik.WinControls.UI.ListViewCellFormattingEventArgs)
Handles
lvLista.CellFormatting
If
TypeOf
e.CellElement
Is
DetailListViewHeaderCellElement
Then
Return
End
If
Dim
dataCell
As
DetailListViewDataCellElement = e.CellElement
Select
Case
e.CellElement.Data.HeaderText
Case
"Número"
e.CellElement.TextAlignment = ContentAlignment.MiddleCenter
dataCell.Text = Format(dataCell.Row(e.CellElement.Data.Name),
"000000"
)
e.CellElement.ImageIndex = dataCell.Row(
"Imagen"
)
Case
"Fecha"
e.CellElement.TextAlignment = ContentAlignment.MiddleCenter
dataCell.Text = Format(dataCell.Row(e.CellElement.Data.Name),
"dd/MM/yyyy"
)
Case
Else
e.CellElement.TextAlignment = ContentAlignment.MiddleLeft
End
Select
End
Sub
0
Hi Javier,
Thank you for writing.
While your approach will work and the image will be assigned correctly, I would suggest using the ItemDataBound event to assign your images for better performance. ItemDataBound event is fired when an item is data bound, while the formatting event is constantly fired.
If you need more information about the control and its functionalities, feel free to take a look at our online documentation: http://www.telerik.com/help/winforms/listview-getting-started.html.
Should you have any further questions, do not hesitate to contact us.
Regards,
Plamen
the Telerik team
Thank you for writing.
While your approach will work and the image will be assigned correctly, I would suggest using the ItemDataBound event to assign your images for better performance. ItemDataBound event is fired when an item is data bound, while the formatting event is constantly fired.
If you need more information about the control and its functionalities, feel free to take a look at our online documentation: http://www.telerik.com/help/winforms/listview-getting-started.html.
Should you have any further questions, do not hesitate to contact us.
Regards,
Plamen
the Telerik team
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 29 Nov 2012, 08:56 PM
I had previously tried that approach, but I couldn't find a way to retrieve the values from the columns I needed. Any ideas?
Thanks.
Thanks.
0
Accepted
Hi Javier,
Thank you for writing back.
In order to retrieve the desired value from the column, you can use the DataBoundItem property of the Item, which is in fact the DataRowView of this item. Here is an example:
I hope that you find this information helpful. Let us know if you need anything else.
Regards,
Plamen
the Telerik team
Thank you for writing back.
In order to retrieve the desired value from the column, you can use the DataBoundItem property of the Item, which is in fact the DataRowView of this item. Here is an example:
Private
Sub
radListView1_ItemDataBound(sender
As
Object
, e
As
ListViewItemEventArgs)
Dim
rowView
As
DataRowView =
DirectCast
(e.Item.DataBoundItem, DataRowView)
e.Item.ImageIndex =
CInt
(rowView.Row(
"Imagen"
))
End
Sub
I hope that you find this information helpful. Let us know if you need anything else.
Regards,
Plamen
the Telerik team