Hello to all,

i have a question that maybe already has an answer but i can't realy find it. I want to have a ListView with a progressbar for each item (row) in this ListView. I have an application where i'm downloading some files to a electronic device i made. And now i'm working on a programm that will interact with my device. And when i'm sending a file to my device i want to se the progress of transfering this file. Doe's anybody have an idea how to embedd a progressbar in a listview control (in a specific column) in VB.NET 2005? Thank you very much.

Best regards,

Borut

Recommended Answers

All 8 Replies

I think I'd make a custom control that copies a listview except instead of text items it contains user controls with all of the stuff you want in them. You probably want more than just a progress bar and doing it with user controls means you can do more and make your application look unique.

Hamrick,

can you explain a little bit more? Were you thinking of making a new class that inherits the Listview class and then add a progressbar? I'm not an expert on VB.NET (my previous programming experience was programming ARM microcontrollers in C).

Thank you.

if you want the quick and rough way. add your progress bar to the form (dynamically would be best as you may have more than one row) then adjust its position relative to the listview. if you have added your progress bar to the listview control it will already have a fixed relative position to that of the parent control. only thing left to do then is update the progress loader.

Were you thinking of making a new class that inherits the Listview class and then add a progressbar?

You don't even need to go that far. You can make a user control that has the progress bar and text boxes and other stuff you want for each line and then add those guys to the Controls collection of a panel.

First I have to read some stuff about user controls - haven't used them so far. Any suggestions for a quick start? :) Thank you all for your answers.

Public Function ListView_AddProgressBar(ByRef pListView As System.Windows.Forms.ListView, ByVal ListViewItemIndex As Integer, ByVal ColumnIndex As Integer) As System.Windows.Forms.ProgressBar
        Dim r As Rectangle
        Dim pb As New System.Windows.Forms.ProgressBar

        r = pListView.Items(ListViewItemIndex).Bounds()
        r.Width = pListView.Columns(ColumnIndex).Width
        If ColumnIndex > 0 Then
            r.X = r.X + pListView.Columns(ColumnIndex - 1).Width
        End If
        pb.Parent = pListView
        pb.SetBounds(r.X, r.Y, r.Width, r.Height)
        pb.Visible = True

        Return pb
    End Function

Author:FreeZeBiT
vbfrance.com

Thank you. But i decided to go with the Qt as it is more powwrfull than VB and it also has all this stuff already made. I did the same this in Qt much much faster.

Thank you all and have a nice day.

Public Function ListView_AddProgressBar(ByRef pListView As System.Windows.Forms.ListView, ByVal ListViewItemIndex As Integer, ByVal ColumnIndex As Integer) As System.Windows.Forms.ProgressBar
Dim r As Rectangle
Dim pb As New System.Windows.Forms.ProgressBar

r = pListView.Items(ListViewItemIndex).Bounds()
r.Width = pListView.Columns(ColumnIndex).Width
If ColumnIndex > 0 Then
r.X = r.X + pListView.Columns(ColumnIndex - 1).Width
End If
pb.Parent = pListView
pb.SetBounds(r.X, r.Y, r.Width, r.Height)
pb.Visible = True

Return pb
End Function

Author:FreeZeBiT
vbfrance.com

This looks like it works fine, and I'm able to use it to add any control. However, the control is being placed statically within the listview, and doesn't move as I scroll. Does anyone have a suggestion on how to handle this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.