Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to show icon in "ListView SubIem " ?
 

How to show icon in "ListView SubIem " ?

How to show an icons for one of the SUBITEM of listview.? pla chk image ->
http://94.76.212.176/$sitepreview/dotnetdev.com/images/ListView%20Query.bmp
I got there is imageList but this will show icon to ListVIewItem... but I want to show to ListViewSubItem.
One of the image is animated Gif.

I want to show 3 icons for 3 ListViewSubItem in the Listview control.

Tejaswini Prashant J  Thursday, September 03, 2009 10:20 AM
Hi Tejaswini,

We can set the OwnerDraw property to true and handle the DrawSubItem event to draw icon in a SubItem. This is the introduction of the OwnerDraw property and a sample:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ownerdraw.aspx.

To draw gif animation, we need to use the ImageAnimator class. This thread talks about how to draw a gif:
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/0d9e790e-6816-40e7-96fe-bbf333a4abc0/.

Let me know if this does not help.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 5:42 AM
Hi Tejaswini,

1. Shall I use ListView Control / DatGridView.
If you need to show data in other views by setting the View property of the ListView, I prefer ListView. If not, DataGridView is better.
2. If I am using ListView Shal I go for virtual mode for better performance.
The performace can be affected by so many kind of items. You can track your code to find out which part of your code is the bottleneck ofthe performance. If the count of the itemsin ListView is very large and it costs too much time to load the items, you can go for virtual mode to improve the performance.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 8:46 AM
Hi Tejaswini,

We can set the OwnerDraw property to true and handle the DrawSubItem event to draw icon in a SubItem. This is the introduction of the OwnerDraw property and a sample:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ownerdraw.aspx.

To draw gif animation, we need to use the ImageAnimator class. This thread talks about how to draw a gif:
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/0d9e790e-6816-40e7-96fe-bbf333a4abc0/.

Let me know if this does not help.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 5:42 AM
Hi Aland,
Thanks for your response.
Now I got to know if I want to draw Image I have to set OwnerDraw Mode ->True.
But for that I have to draw the list again..is it rite?
And I tried using OwnerDraw Mode it flickers alot.
That to I want my listview control content must be refreshed after every one second.
How should I proceed with listview and ownerdraw mode? or shall i use DatGridView control?

Tejaswini Prashant J  Monday, September 07, 2009 7:40 AM
Hi Tejaswini,

1. But for that I have to draw the list again..is it rite?
Yes, you need to draw the list again.
2.And I tried using OwnerDraw Mode it flickers alot.
We can enable double buffering to reduce flickers, this is a code snippet:
    public class NewListView : ListView
    {
        public NewListView()
        {
            //Enable these styles to reduce flicker
            //1. Enable user paint.
            this.SetStyle(ControlStyles.UserPaint, true);
            //2. Enable double buffer.
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            //3. Ignore a windows erase message to reduce flicker.
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        }
    }
3. or shall i use DatGridView control?
You can use the DataGridView. In this way, you need to handle the CellPaint method to draw an image. You can get more information about CellPaint event from:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellpainting.aspx

Let me know if this helps or not.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 7:51 AM
Hi,
I am working on a project of Live Support.
I am developing the support console in .net windows. In the operator console I want to show All Live clients for my site.
And right now I am showing all these clients in ListView control. The information of the client I want to show will contain Text and small images.

As per the requirement I am refreshing the list every second.
So in this scenario
1. Shall I use ListView Control / DatGridView
2. If I am using ListView Shal I go for virtual mode for better performance.

Tejaswini Prashant J  Monday, September 07, 2009 8:29 AM
Hi Tejaswini,

1. Shall I use ListView Control / DatGridView.
If you need to show data in other views by setting the View property of the ListView, I prefer ListView. If not, DataGridView is better.
2. If I am using ListView Shal I go for virtual mode for better performance.
The performace can be affected by so many kind of items. You can track your code to find out which part of your code is the bottleneck ofthe performance. If the count of the itemsin ListView is very large and it costs too much time to load the items, you can go for virtual mode to improve the performance.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Monday, September 07, 2009 8:46 AM

You can use google to search for other answers

Custom Search

More Threads

• Select the row in the DataGrid
• Add values in DataColumns rows
• Server to Client Chat only
• Set BindingSource.DataSource to null
• Disallow new row in Datagrid
• Text and linkbutton on the same column of datagridview
• SelectedIndexEvent for DataGridViewComboBoxCell
• Create 1 dataset from 2 datasets and showing in Datagridview
• cannot connect to Database
• Merging 2 dataset