473,409 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

The ListView Control

Dom
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().

Aug 30 '07 #1
3 1978
Hi,

"Dom" <do********@gmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
>
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.
Aug 30 '07 #2
Dom
On Aug 30, 1:40 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,

"Dom" <dolivas...@gmail.comwrote in message

news:11**********************@r29g2000hsg.googlegr oups.com...
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.
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

Aug 30 '07 #3
Hi,

"Dom" <do********@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
On Aug 30, 1:40 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
>Hi,

"Dom" <dolivas...@gmail.comwrote in message

news:11**********************@r29g2000hsg.googleg roups.com...
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.

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.
Ok, just remember that you need to have the same number of columns
Aug 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below....
2
by: Ken | last post by:
Hi all, Please help! I'm attempting to apply tooltips to each individual item in VB.Net's Listview control. In VB6 it was easy - you just did the following (assumes "myListView" is the name of...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
4
by: Pucca | last post by:
How can I tell a mouse right clicks over a listview item that's in a container panel. I only want to display a popup menu if the user right click the mouse over an item on the Listview. I don't...
3
by: Michael.Suarez | last post by:
Is it me, or does it seem like they put no effort into creating the listview control in .Net. listview. A few gripes I have with .Net listview that aren't present in vb6: -Inability to set...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
10
by: Rob | last post by:
VS 2005 How can you tell if a value is contained in a specific column (let's say column 1 named Status) of a ListView ? In a list box you could go... If ListBox1.Items.Contains(strWhatever)...
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
0
by: =?Utf-8?B?SWdvcg==?= | last post by:
Hi everyone! I have some strange behavior of ListView control in WPF. We are developing application in C#. I created ListView with some items and set SelectedIndex to some index in the...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.