none
how to draw image to subitem in listview in VB ? RRS feed

  • Question

  • hi All 

    i would like to add image to subitem , the best solution i found here is from Reed Kimble:

     Private Sub ListView1_DrawColumnHeader(ByVal sender As ObjectByVal e AsSystem.Windows.Forms.DrawListViewColumnHeaderEventArgs) HandlesListView1.DrawColumnHeader

            e.DrawDefault = True

        End Sub

     

        Private Sub ListView1_DrawSubItem(ByVal sender As ObjectByVal e AsSystem.Windows.Forms.DrawListViewSubItemEventArgs) HandlesListView1.DrawSubItem

     

            If Not e.Item.SubItems(0) Is e.SubItem Then

                e.DrawDefault = False

                e.DrawBackground()

                e.Graphics.DrawImage(My.Resources.Image1, e.SubItem.Bounds.Location)

                e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, NewSolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X +My.Resources.Image1.Width, e.SubItem.Bounds.Location.Y)

            Else

                e.DrawDefault = True

            End If

     but i have 2 problems :

    1- i need just to draw the image for the selected subitems.

    2- the draw should done when the user press a Button

    Visual Studio 2013

    help please

    Thanks in advance

    Monday, July 28, 2014 1:24 AM

Answers

  • Hi,

     Here is a new version that will let you set one, two, or all three images to one item or however many you have selected. I made it so they can be shown if they are not shown or to not show them if they are shown by clicking the contextmenu item. I changed the way the drawing info is used, it is now a small private class that contains 3 Boolean variables and assign the class to the ListViewItem`s Tag property. I also showed how to set the images you want to show in the Form.Load event when the Items are being added to the ListView. I am sure there are other ways to do the same thing but, this is what came to mind first.

     There are ways to actually save all the items of the ListView to a Binary file and have them reloaded when the app starts the next time so that all the Items info including the Tag property is saved. I didn`t put that in this code but, can show an example of how to do it.

    If you are starting a new Form project for this example then use the instructions from my last example to add the lView class and build the project before adding the Forms code.   8)

    Public Class Form1
    
        Private Class DrawInfo
            Public Flag As Boolean
            Public Read As Boolean
            Public Done As Boolean
        End Class
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LView1.ContextMenuStrip = ContextMenuStrip1
            LView1.OwnerDraw = True
            LView1.FullRowSelect = True
            LView1.Font = New Font(LView1.Font.Name, 9, FontStyle.Bold)
    
            'This loop is to show how you could set the different images to be drawn when loading items
            For x As Integer = 0 To 5
                Dim lvi As New ListViewItem("Item " & x.ToString)
                lvi.SubItems.Add("SubItem 1")
                lvi.SubItems.Add("SubItem 2")
                lvi.SubItems.Add("SubItem 3")
                lvi.SubItems.Add("SubItem 4")
                lvi.SubItems.Add("SubItem 5")
    
                Dim di As New DrawInfo 'Create a new DrawInfo
                di.Flag = True 'Set whatever images should be drawn (Flag, Read, or Done)
                di.Read = False
                di.Done = False
                lvi.Tag = di 'Add the DrawInfo to the ListViewItem`s Tag property
    
                LView1.Items.Add(lvi)
            Next
        End Sub
    
        Private Sub ListView1_DrawColumnHeader(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles LView1.DrawColumnHeader
            e.DrawDefault = True
        End Sub
    
        Private Sub ListView1_DrawSubItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles LView1.DrawSubItem
            e.DrawDefault = False
            e.DrawBackground()
            Using txtbrsh As New SolidBrush(e.SubItem.ForeColor)
                If LView1.SelectedIndices.Contains(e.ItemIndex) Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.FromKnownColor(KnownColor.Highlight)), e.Bounds)
                    txtbrsh.Color = Color.White
                End If
                If e.Item.Tag IsNot Nothing Then
                    Dim di As DrawInfo = CType(e.Item.Tag, DrawInfo)
                    If di.Flag And e.Item.SubItems(0) Is e.SubItem Then
                        e.Graphics.DrawImage(ImageList1.Images(0), e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                    End If
                    If di.Read And e.Item.SubItems(1) Is e.SubItem Then
                        e.Graphics.DrawImage(ImageList1.Images(1), e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                    End If
                    If di.Done And e.Item.SubItems(5) Is e.SubItem Then
                        e.Graphics.DrawImage(ImageList1.Images(2), e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                    End If
                    e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, txtbrsh, e.SubItem.Bounds.Location.X + e.Bounds.Height, e.SubItem.Bounds.Location.Y)
                Else
                    e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, txtbrsh, e.SubItem.Bounds.Location.X + e.Bounds.Height, e.SubItem.Bounds.Location.Y)
                End If
            End Using
        End Sub
    
        Private Sub FlagToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlagToolStripMenuItem.Click
            AddDrawInfo(0)
        End Sub
    
        Private Sub ReadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadToolStripMenuItem.Click
            AddDrawInfo(1)
        End Sub
    
        Private Sub DoneToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DoneToolStripMenuItem.Click
            AddDrawInfo(5)
        End Sub
    
        Private Sub AddDrawInfo(ByVal subIndx As Integer)
            If LView1.SelectedItems.Count > 0 Then
                For Each lvi As ListViewItem In LView1.SelectedItems
                    Dim di As New DrawInfo
                    If lvi.Tag IsNot Nothing Then
                        di = CType(lvi.Tag, DrawInfo)
                    End If
                    If subIndx = 0 Then di.Flag = Not di.Flag
                    If subIndx = 1 Then di.Read = Not di.Read
                    If subIndx = 5 Then di.Done = Not di.Done
                    If di.Flag Or di.Read Or di.Done Then
                        lvi.Tag = di
                    Else
                        lvi.Tag = Nothing
                    End If
                Next
                LView1.Refresh()
            End If
        End Sub
    End Class
    
    Public Class LView
        Inherits ListView
    
        Public Sub New()
            Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        End Sub
    End Class


    If you say it can`t be done then i`ll try it

    Tuesday, July 29, 2014 8:49 PM

All replies

  • Hi,

     The info you gave us on how you want it to work is not real clear but, here is an example of how you can do it. This will add the image to the subitem when the item is selected and you press the button. You must have the listview`s View property set to Details and you must have 2 columns added to it. Also you need a small image added to the projects resources for this example. I used one that is 20x20. You may need to experiment with the width and height parameters of the e.Graphics.DrawImage method to get things rite for your images width to height ratio if it is not square like mine is.

    Public Class Form1
        Private DrawImageIndex As New List(Of Integer)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListView1.OwnerDraw = True
    
            'This loop is only to add some items to the listview for this example
            For x As Integer = 0 To 9 Step 2
                Dim lvi As New ListViewItem("Item " & x.ToString)
                lvi.SubItems.Add("SubItem " & (x + 1).ToString)
                ListView1.Items.Add(lvi)
            Next
        End Sub
    
        Private Sub ListView1_DrawColumnHeader(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader
            e.DrawDefault = True
        End Sub
    
        Private Sub ListView1_DrawSubItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
            If Not e.Item.SubItems(0) Is e.SubItem And DrawImageIndex.Contains(e.ItemIndex) Then
                e.DrawDefault = False
                e.DrawBackground()
                e.Graphics.DrawImage(My.Resources.FolderImage, e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, New SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + My.Resources.FolderImage.Width, e.SubItem.Bounds.Location.Y)
            ElseIf Not e.Item.SubItems(0) Is e.SubItem Then
                e.DrawDefault = False
                e.DrawBackground()
                e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, New SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X + My.Resources.FolderImage.Width, e.SubItem.Bounds.Location.Y)
            Else
                e.DrawDefault = True
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If ListView1.SelectedItems.Count > 0 Then
                For Each si As Integer In ListView1.SelectedIndices
                    If Not DrawImageIndex.Contains(si) Then DrawImageIndex.Add(si)
                Next
                ListView1.Refresh()
            End If
        End Sub
    End Class
    


    If you say it can`t be done then i`ll try it

    Monday, July 28, 2014 4:04 AM
  • Some seem to forget that the ListView is just the right pane from windows explorer (file explorer since version W8).

    It can be shown in more ways. 

    For instance

    • detail 
    • Small images
    • Medium images
    • Large images
    • list

    But that is all about the Items, not the subitems, that are the details in list and detail view.

    It seems you use the ListView like a Grid but for that are complete different controls.


    Success
    Cor

    Monday, July 28, 2014 8:24 AM
  • Thanks for the information but as you said it's for Items not subitems . 
    Monday, July 28, 2014 4:45 PM
  • Thanks for the information but as you said it's for Items not subitems . 

    Please try to provide a better explanation of what you mean... from what I can gather from your question I would appear that IronRazerz' answer does as you requested.  If that isn't what you mean, can you mock up an image of what you are referring to?


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, July 28, 2014 4:52 PM
    Moderator
  • Thanks IronRazerz 

    first i'm sorry i didn't clear in the main post.

    i still need your help a little bit 

    i have 6 columns in the list view and ContextMenuStrip with items, each item will represent an image in one of the column ( subitem(0) , or sumitem(1) ........), and an imagelist with the photos 

    to be honest your code answer my first question exactly, but when i'm trying to edit it to fit my needs i'm totally lost , i just change it to take the image from imagelist but i'm still lost in the following :

    1- the image appear in all subitems .

    what i'm really need is to draw it ,  just for (subitem(0) > which represent coulmn 2 in the listview , or subitem(1) > which represent coulmn 3 in the listview ....... and so on)

    2- how to make it more than one function

    so when i'm select the ToolStripMenuItem from ContextMenuStrip . draw the correct image  

    thanks again , and hope you can help me again .


    • Edited by Saiomn Monday, July 28, 2014 4:59 PM correction
    Monday, July 28, 2014 4:59 PM
  • Hi Reed Kimble 

    first of all i would like to thank you about your idea of how to draw image in subitems , before i saw it i feel like it is impossible to do that  until i see your code it's give me the hope to make the work done  , also for crop photos code in one of the threads it's the best code.  

    second i'm really sorry for my bad explanation in the main post , in next time i will do my best to explain what exactly i need to do .

    here exactly what i need :

    have 6 columns in the list view and ContextMenuStrip with items, each item will represent an image in one of the column ( subitem(0) , or sumitem(1) ........), and an imagelist with the photos 

    to be honest your code answer my first question exactly, but when i'm trying to edit it to fit my needs i'm totally lost , i just change it to take the image from imagelist but i'm still lost in the following :

    1- the image appear in all subitems .

    what i'm really need is to draw it ,  just for (subitem(0) > which represent coulmn 2 in the listview , or subitem(1) > which represent coulmn 3 in the listview ....... and so on)

    2- how to make it more than one function

    so when i'm select the ToolStripMenuItem from ContextMenuStrip . draw the correct image from imagelist


    • Edited by Saiomn Monday, July 28, 2014 5:10 PM correction
    Monday, July 28, 2014 5:10 PM
  • Hi,

     I still don`t understand exactly what you are trying to do so, let me get this rite before i go creating a new code example.

     

     If i select (Row3) and then select (Menu Item 1) in the contextmenu should it show the first image in the imagelist on SubItem1 of Row3 ?

     If i select (Row3) and then select (Menu Item 2) in the contextmenu should it show the second image in the imagelist on SubItem2 of Row3 ?


    If you say it can`t be done then i`ll try it

    Monday, July 28, 2014 7:03 PM
  • here is all the details :

    i have listview wtih 6 columns ( column0>Flag , column1>read , ...............column5> Done )

    and imagelist1 include images .

    and contextmenustrip inculde the following items( Flag , Read, Done )

    what i need to do :

    - if the user select "Flag" from contextmenu >>> the ImageList1.Images.Item(1) will show in the column0 "flag"

    - if the user select "read" from contextmenu >>> the ImageList1.Images.Item(2) will show in the column1 "read"

    - if the user select "Done" from contextmenu >>> the ImageList1.Images.Item(3) will show in the column5 "Done"

    sorry i can't post photo because my account not verified .

    Thanks for your effort Iron

    Monday, July 28, 2014 8:04 PM
  • Ok, that explanation made it a lot clearer. I will see what i can come up with. It might be an hour or two before i post an example.  8)

    If you say it can`t be done then i`ll try it

    Monday, July 28, 2014 8:15 PM
  • Hi,

     Well, i managed to get this working but, being that i had to draw all the items/subitems in the listview i found that if you use a standard listview it flickers every time it repaints itself when you select an item or set the image for an item. It looked kind of crappy so, i had to create a small listview class so i could make it DoubleBuffered which stops it from flickering when it repaints itself. You can simply add the class to the bottom of your forms code and build the project before adding any of the forms code that i will show.

     Here is what you need to do. Start a new Form project and go rite to the Code view tab and add the LView class rite under the forms empty class code like shown here.

    Public Class Form1
    
    End Class
    
    Public Class LView
        Inherits ListView
    
        Public Sub New()
            Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        End Sub
    End Class
     

     Now you can go to the VB menu and click (Build) and then select (Build Name of your project). When it is done building the project go to the forms Design tab and drag an LView control from the Toolbox onto your form and add 6 columns to it. That takes care of adding the double buffered ListView class to your project.

     Now you can drag 1 ImageList and 1 ContextMenu onto the form. Don`t rename anything or set any properties for these controls. Just add 3 items in the ContextMenu in this order (Flag, Read, and Done). Then click on the ImageList and add your 3 images. Make sure they are arranged in the order of (Flag image, Read image, and Done image).

    Now you can add the the code below to your form but, do not remove the LView class code that you have already added.

    Public Class Form1
        Private DrawInfo As New Dictionary(Of Integer, Integer)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LView1.ContextMenuStrip = ContextMenuStrip1
            LView1.OwnerDraw = True
            LView1.FullRowSelect = True
            LView1.Font = New Font(LView1.Font.Name, 9, FontStyle.Bold)
    
            'This loop is only to add some items to the listview for this example
            For x As Integer = 0 To 5
                Dim lvi As New ListViewItem("Item " & x.ToString)
                lvi.SubItems.Add("SubItem 1")
                lvi.SubItems.Add("SubItem 2")
                lvi.SubItems.Add("SubItem 3")
                lvi.SubItems.Add("SubItem 4")
                lvi.SubItems.Add("SubItem 5")
                LView1.Items.Add(lvi)
            Next
        End Sub
    
        Private Sub ListView1_DrawColumnHeader(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles LView1.DrawColumnHeader
            e.DrawDefault = True
        End Sub
    
        Private Sub ListView1_DrawSubItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles LView1.DrawSubItem
            e.DrawDefault = False
            e.DrawBackground()
            Using txtbrsh As New SolidBrush(e.SubItem.ForeColor)
                If LView1.SelectedIndices.Contains(e.ItemIndex) Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.FromKnownColor(KnownColor.Highlight)), e.Bounds)
                    txtbrsh.Color = Color.White
                End If
                If DrawInfo.ContainsKey(e.ItemIndex) AndAlso e.Item.SubItems(DrawInfo.Item(e.ItemIndex)) Is e.SubItem Then
                    Dim idx As Integer = DrawInfo.Item(e.ItemIndex)
                    If idx = 5 Then idx = 2
                    e.Graphics.DrawImage(ImageList1.Images(idx), e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                    e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, txtbrsh, e.SubItem.Bounds.Location.X + e.Bounds.Height, e.SubItem.Bounds.Location.Y)
                Else
                    e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, txtbrsh, e.SubItem.Bounds.Location.X + e.Bounds.Height, e.SubItem.Bounds.Location.Y)
                End If
            End Using
        End Sub
    
        Private Sub FlagToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlagToolStripMenuItem.Click
            AddDrawInfo(0)
        End Sub
    
        Private Sub ReadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadToolStripMenuItem.Click
            AddDrawInfo(1)
        End Sub
    
        Private Sub DoneToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DoneToolStripMenuItem.Click
            AddDrawInfo(5)
        End Sub
    
        Private Sub AddDrawInfo(ByVal subIndex As Integer)
            If LView1.SelectedItems.Count > 0 Then
                For Each si As Integer In LView1.SelectedIndices
                    If DrawInfo.ContainsKey(si) Then
                        DrawInfo.Item(si) = subIndex
                    Else
                        DrawInfo.Add(si, subIndex)
                    End If
                Next
                LView1.Refresh()
            End If
        End Sub
    End Class
    
     

     Now save your project and then debug (Run) the application and test it out.   8)


    If you say it can`t be done then i`ll try it

    Monday, July 28, 2014 11:56 PM
  • Good job IronRazerz, I think this demonstrates the general idea.  There are a number of ways to go about it but the point is that there needs to be some additional information stating which image (if any) should be associated with each sub item.  Then the draw routine can simply analyze this information to determine what image to use.  The OP may still need a little assistance getting it exactly as they want (I'm not clear if there is text or not, but that's just a matter of modifying what's drawn) but this should be a good start.

    The one thing I'd add is, don't forget that you can use reflection to call an internal object member.  So you could get the non-public, instance method named "SetStyle" from the ListView type and then invoke the method against the existing instance of the ListView control (just like the code I used in this thread about the MDI Form resizing issue).


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, July 29, 2014 3:16 AM
    Moderator
  • i'm almost have the same issue . i need to use draw image to sub items , but i need to draw images when the form load . also after that i will use the same method to draw more images.

    i tested your code it's working prefect , how to use it when form loaded , so some images will draw directly without any action from the user .and how can i make it draw more than one image in the same row  for different sub items in the same row lets say i need to draw flag and read in the row three .

    Tuesday, July 29, 2014 9:14 AM
  • @Reed,

     You know.... i actually thought about that but, was not familiar with doing it. I will have to take another look at that MDI thread and do a little playing around with using that method. Being i was used to making classes and it was getting late i just did it that way. Thanks for the tip Reed.  8)


    If you say it can`t be done then i`ll try it

    Tuesday, July 29, 2014 10:08 AM
  • @ samehshams,

     I have to go to work for a while but, when i get home later i will see what i can do to make it show more than one image on each item row. To show the images when it starts you have to know somehow which items need which images and use the Form.Load event to load that information and set it by calling the AddDrawInfo sub but, i will need to redesign that sub so that the Item row index can be passed to it and make it hold more than 1 image index for each item row.   :)


    If you say it can`t be done then i`ll try it

    Tuesday, July 29, 2014 10:20 AM
  • Thanks IronRazerz
    Tuesday, July 29, 2014 11:08 AM
  • Hi,

     Here is a new version that will let you set one, two, or all three images to one item or however many you have selected. I made it so they can be shown if they are not shown or to not show them if they are shown by clicking the contextmenu item. I changed the way the drawing info is used, it is now a small private class that contains 3 Boolean variables and assign the class to the ListViewItem`s Tag property. I also showed how to set the images you want to show in the Form.Load event when the Items are being added to the ListView. I am sure there are other ways to do the same thing but, this is what came to mind first.

     There are ways to actually save all the items of the ListView to a Binary file and have them reloaded when the app starts the next time so that all the Items info including the Tag property is saved. I didn`t put that in this code but, can show an example of how to do it.

    If you are starting a new Form project for this example then use the instructions from my last example to add the lView class and build the project before adding the Forms code.   8)

    Public Class Form1
    
        Private Class DrawInfo
            Public Flag As Boolean
            Public Read As Boolean
            Public Done As Boolean
        End Class
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            LView1.ContextMenuStrip = ContextMenuStrip1
            LView1.OwnerDraw = True
            LView1.FullRowSelect = True
            LView1.Font = New Font(LView1.Font.Name, 9, FontStyle.Bold)
    
            'This loop is to show how you could set the different images to be drawn when loading items
            For x As Integer = 0 To 5
                Dim lvi As New ListViewItem("Item " & x.ToString)
                lvi.SubItems.Add("SubItem 1")
                lvi.SubItems.Add("SubItem 2")
                lvi.SubItems.Add("SubItem 3")
                lvi.SubItems.Add("SubItem 4")
                lvi.SubItems.Add("SubItem 5")
    
                Dim di As New DrawInfo 'Create a new DrawInfo
                di.Flag = True 'Set whatever images should be drawn (Flag, Read, or Done)
                di.Read = False
                di.Done = False
                lvi.Tag = di 'Add the DrawInfo to the ListViewItem`s Tag property
    
                LView1.Items.Add(lvi)
            Next
        End Sub
    
        Private Sub ListView1_DrawColumnHeader(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs) Handles LView1.DrawColumnHeader
            e.DrawDefault = True
        End Sub
    
        Private Sub ListView1_DrawSubItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles LView1.DrawSubItem
            e.DrawDefault = False
            e.DrawBackground()
            Using txtbrsh As New SolidBrush(e.SubItem.ForeColor)
                If LView1.SelectedIndices.Contains(e.ItemIndex) Then
                    e.Graphics.FillRectangle(New SolidBrush(Color.FromKnownColor(KnownColor.Highlight)), e.Bounds)
                    txtbrsh.Color = Color.White
                End If
                If e.Item.Tag IsNot Nothing Then
                    Dim di As DrawInfo = CType(e.Item.Tag, DrawInfo)
                    If di.Flag And e.Item.SubItems(0) Is e.SubItem Then
                        e.Graphics.DrawImage(ImageList1.Images(0), e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                    End If
                    If di.Read And e.Item.SubItems(1) Is e.SubItem Then
                        e.Graphics.DrawImage(ImageList1.Images(1), e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                    End If
                    If di.Done And e.Item.SubItems(5) Is e.SubItem Then
                        e.Graphics.DrawImage(ImageList1.Images(2), e.SubItem.Bounds.X, e.SubItem.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
                    End If
                    e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, txtbrsh, e.SubItem.Bounds.Location.X + e.Bounds.Height, e.SubItem.Bounds.Location.Y)
                Else
                    e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, txtbrsh, e.SubItem.Bounds.Location.X + e.Bounds.Height, e.SubItem.Bounds.Location.Y)
                End If
            End Using
        End Sub
    
        Private Sub FlagToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlagToolStripMenuItem.Click
            AddDrawInfo(0)
        End Sub
    
        Private Sub ReadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadToolStripMenuItem.Click
            AddDrawInfo(1)
        End Sub
    
        Private Sub DoneToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DoneToolStripMenuItem.Click
            AddDrawInfo(5)
        End Sub
    
        Private Sub AddDrawInfo(ByVal subIndx As Integer)
            If LView1.SelectedItems.Count > 0 Then
                For Each lvi As ListViewItem In LView1.SelectedItems
                    Dim di As New DrawInfo
                    If lvi.Tag IsNot Nothing Then
                        di = CType(lvi.Tag, DrawInfo)
                    End If
                    If subIndx = 0 Then di.Flag = Not di.Flag
                    If subIndx = 1 Then di.Read = Not di.Read
                    If subIndx = 5 Then di.Done = Not di.Done
                    If di.Flag Or di.Read Or di.Done Then
                        lvi.Tag = di
                    Else
                        lvi.Tag = Nothing
                    End If
                Next
                LView1.Refresh()
            End If
        End Sub
    End Class
    
    Public Class LView
        Inherits ListView
    
        Public Sub New()
            Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        End Sub
    End Class


    If you say it can`t be done then i`ll try it

    Tuesday, July 29, 2014 8:49 PM
  • Thanks IronRazerz 

    for your effort and the information , i learnt a lot of things from You.

    a Lot of thanks

    Wednesday, July 30, 2014 5:11 AM
  • Thanks IronRazerz 

    for your effort and the information , i learnt a lot of things from You.

    a Lot of thanks


     Your Welcome. Glad i could help.   8)

    If you say it can`t be done then i`ll try it

    Wednesday, July 30, 2014 9:40 AM
  • @IronRazers

    Nicely done, however it falls for me in the category. 

    If you say it can`t be done then i`ll try it

    If somebody ask you how to hammer a nail with a screwdriver, you will come in my idea also with a solution.

    :-)


    Success
    Cor

    Wednesday, July 30, 2014 9:49 AM
  • @IronRazers

    Nicely done, however it falls for me in the category. 

    If you say it can`t be done then i`ll try it

    If somebody ask you how to hammer a nail with a screwdriver, you will come in my idea also with a solution.

    :-)


    Success
    Cor


     Sorry it does not meet your specs. That is what they asked about and that`s what i gave them. Maybe they liked the look of the ListView control and that is what they wanted. They didn`t ask if there was another control to do this better.  8)

    If you say it can`t be done then i`ll try it

    Wednesday, July 30, 2014 10:38 AM
  • @IronRazerz,

    The code does meet my specs, the solution not, I could not propose it as answer otherwise I had done that. I only could vote for it as helpful.

    Nevertheless is in my perception the listview not the right tool for this, therefore I try to warn users. In VB6 there was nothing better, so many take still this one.

    :-)


    Success
    Cor

    Wednesday, July 30, 2014 11:36 AM
  • @ Cor Ligthert 

    Can i know what is the right tool! 

    Thanks in advance


    • Edited by samehshams Wednesday, July 30, 2014 3:09 PM
    Wednesday, July 30, 2014 3:07 PM
  • @ Cor Ligthert 

    Can i know what is the right tool! 

    Thanks in advance


    No, this is already an hacked thread, it would be better if a moderator marks the most correct replies from Ironrazer as answer. I would suggest that in this case Ironrazerz propose those himself and chooses the best ones.

    If you have a problem then describe what you want to achieve in a new thread and ask how that can be solved.


    Success
    Cor


    Wednesday, July 30, 2014 3:18 PM
  • @ Cor Ligthert 

    Can i know what is the right tool! 

    Thanks in advance


    No, this is already an hacked thread, it would be better if a moderator marks the most correct replies from Ironrazer as answer. I would suggest that in this case Ironrazerz propose those himself and chooses the best ones.

    If you have a problem then describe what you want to achieve in a new thread and ask how that can be solved.


    Success
    Cor


    thanks 

    i asked because i would like to know all possible solution that may help me later with programming.

    Wednesday, July 30, 2014 3:42 PM