Help with some code

J

John Rogers

I just found this code and I am eager to get it working to
see if it really works. I am having a few problems with
some lines that are not referencing peoperly. Can someone
show me how to correct these errors.

..Items and .Columns the compiler does not like.

public System.Windows.Forms.ProgressBar ListView_AddProgressBar(ref
System.Windows.Forms.ListView pListView, int ListViewItemIndex, int
ColumnIndex)
{
Rectangle r;
System.Windows.Forms.ProgressBar pb = new
System.Windows.Forms.ProgressBar();
// .Items here
r = pListView.Items(ListViewItemIndex).Bounds();
// .Columns here
r.Width = pListView.Columns(ColumnIndex).Width;
if (ColumnIndex > 0)
{
// .Columns here
r.X = r.X + pListView.Columns(ColumnIndex - 1).Width;
}
pb.Parent = pListView;
pb.SetBounds(r.X, r.Y, r.Width, r.Height);
pb.Visible = true;
return pb;
}

Appreciate it

John-
 
M

Marc Gravell

VB background?

In C#, indexers use square brackets - so this would
be .Items[ListViewItemIndex] and .Columns[ColumnIndex]
Also - Bounds is a property (not a method), so lose the
brackets: .Bounds;

Finally, since you aren't *reassigning* pListView, the "ref" is
unnecessary; remove it. It is still only a reference that gets passed
- see here for details: http://www.pobox.com/~skeet/csharp/parameters.html

Marc
 
J

John Rogers

Thanks Marc,

The code was converted from VB to C#, I guess they didn't know the
parameters (like myself).

Thanks for your help.


John-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top