Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

The ListView Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dom - 30 Aug 2007 16:40 GMT
Still making my way through cSharp.  I've started using the ListView
control, and I'm already up against the wall.  My code looks something
like this:

ListViewItem t = new ListViewItem();
for (...)
{
  t.SubItems.Add (...);
}
ListView1.Add (t);

The problem is that the columns of the listview are shifted to the
right by one column.  After debugging around, I found that "t = new
ListViewItem();" shows that t.SubItems.Count = 1.  Where did that "1"
come from?  Shouldn't it be "0"?  It is still there after I do
t.Clear().
Ignacio Machin ( .NET/ C# MVP ) - 30 Aug 2007 18:40 GMT
Hi,

> ListViewItem t = new ListViewItem();
> for (...)
> {
>   t.SubItems.Add (...);
> }
> ListView1.Add (t);

That looks fine, but how many columns do you have? I have never ever had a
need to do a for to add the subitems.

> The problem is that the columns of the listview are shifted to the
> right by one column.  After debugging around, I found that "t = new
> ListViewItem();" shows that t.SubItems.Count = 1.  Where did that "1"
> come from?  Shouldn't it be "0"?  It is still there after I do
> t.Clear().

The first column is ListViewItem.Text, the second column are the SubItems.
Not only that, but  SubItems[0] is the ListViewItem.Text !!!
That explain why t.SubItems.Count  shows 1 instead of 0 as you were
expecting.
Dom - 30 Aug 2007 19:50 GMT
On Aug 30, 1:40 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.com> wrote:
> Hi,
>
[quoted text clipped - 18 lines]
> That explain why t.SubItems.Count  shows 1 instead of 0 as you were
> expecting.

Thanks, Ignacio.  That explains it for me.  For the record, I do a
"for" loop to add the subitems because I don't know how many subitems
I need before hand.  The user enters an Access filename, and then
chooses to list one of the Schema for the file, eg, the tables, or the
indexes.  The information you get for the table (name, creation data,
etc), is not the same as the information you get for the indexes.

But your answer is what I needed.  I'm going to add an initial column
that will just count off the row number.

Thanks, again
Ignacio Machin ( .NET/ C# MVP ) - 30 Aug 2007 20:26 GMT
Hi,

> On Aug 30, 1:40 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
> laceupsolutions.com> wrote:
[quoted text clipped - 32 lines]
> But your answer is what I needed.  I'm going to add an initial column
> that will just count off the row number.

Ok, just remember that you need to have the same number of columns

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.