views:

47

answers:

5

I have an app that requires multiple progress bars to be added dynamically to a form (whenever a new upload is added and started).

I've been Googling and the results suggested embedding progress bars in a ListView or a DataGridView.

Can anyone suggest any other techniques, as neither ListView or DataGridView hacks I've seen so far seem appealing?

+1  A: 

I would recommend creating a custom control, perhaps using a Panel as a base control. Add the controls for the progress bar, file name, other file information, etc.. and expose everything as properties. Write the functions so that they automatically handle their own progress.

This way you can instantiate them like anything else, and add them to a scrolling area, without having to worry too much about the properties of each. This is just a base idea to get you started. Let me know if this isn't clear enough.

Here's one relatively thorough example of creating a custom control: http://www.akadia.com/services/dotnet_user_controls.html

Fosco
I let some so the hard work for me:
johnnyturbo3
http://www.codeproject.com/KB/list/ListViewEmbeddedControls.aspx
johnnyturbo3
A: 

I guess a TableLayoutPanel would be easier.

One column and add a row for each ProgressBar.
Or two columns, one with a Label and one with the ProgressBar.

Albin Sunnanbo
A: 

I personally don't know much about them myself but I think if you used Background workers they mgiht be able to help as you can call a method that notifies the program that progress has been made and with that you can update the progress bar.Background worker

stuartmclark
A: 

If using third party controls is allowed, I would suggest something like XtraGrid from DevEx. It will be so easy to pull off you'll feel you are cheating.

A: 

An alternative is to use a ListView with OwnerDraw property true and respond to the DrawSubItem() event. Drawing a progress bar is supereasy within the given rectangle e.Bounds that is given in the event arguments using the already supplied e.Graphics object.

Here is an example

private void lvUsers_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
    if (e.ColumnIndex == 5)
    {
        e.DrawDefault = false;
        Rectangle bounds = e.Bounds;
        double pct = ...;
        Rectangle fill = new Rectangle(
            bounds.Left, bounds.Top,
            (int)(pct * bounds.Width), bounds.Height);
        using (LinearGradientBrush lg = ...)
        {
            e.Graphics.FillRectangle(lg, fill);
        }
        e.Graphics.DrawRectangle(Pens.Black, bounds);
       ...
    }
    else
    {
        e.DrawDefault = true;
    }
}
jalexiou