|
-
November 20th, 2002, 10:37 PM
#1
ListView Fundamentals :: C#
Hi.
I have some fundamental questions on the listview.
1) I added a listview with some columns, however, the column titles do not appear. The columns are there, but they do not appear. Is there a setting in winform that can hide it?
2) How do you search for an item in the listview?
3) How do you set the text of a specific item in a listview? For example, I want to set the text of item 2 column 1.
Thanks,
Kuphryn
-
November 22nd, 2002, 07:10 AM
#2
I might have the answer for your first question,
ColumnHeader header1 = this.listviewInstances.Columns.Add("C1", 10, HorizontalAlignment.Center);
ColumnHeader header2 = this.listviewInstances.Columns.Add("C2", 10, HorizontalAlignment.Center);
ColumnHeader header3 = this.listviewInstances.Columns.Add("C3", 10, HorizontalAlignment.Center );
ColumnHeader header4 = this.listviewInstances.Columns.Add("C4", 10, HorizontalAlignment.Center );
Hope it helps
/Anders
-
November 22nd, 2002, 09:39 AM
#3
2.) If you need to search for item based on its name, you have to iterate through list view item collection to find some item.
Code:
ListViewItem lvi = null;
string strYourText = "some text";
foreach (ListViewItem _lvi in this.listYourList.Items)
{
if (_lvi.Text == strYourText)
{
lvi = _lvi;
break;
}
}
if (lvi != null)
{
// We found it... lvi is the proper ListViewItem
}
If you need to search alse the subitems, you need to make this searching also on the _lvi.SubItems collection...
3.)
Code:
public void SetListItemText(ListView list, int iItemIndex, int iSubItemIndex, string strNewText)
{
if (list == null)
return;
if (iItemIndex < 0 || iItemIndex >= list.Items.Count)
throw new ArgumentOutOfRangeException("iItemIndex", "Parameter is out of range");
ListViewItem lvi = list.Items[iItemIndex];
if (lvi == null)
return;
if (iSubItemIndex < 0 || iSubItemIndex >= lvi.SubItems.Count)
throw new ArgumentOutOfRangeException("iSubItemIndex", "Parameter is out of range");
ListViewItem lviSubItem = lvi.SubItems[iSubItemIndex];
if (lviSubItem != null)
lviSubItem.Text = strNewText;
}
Martin
-
November 22nd, 2002, 09:40 AM
#4
Additionally, call
Code:
this.listviewInstances.Columns.Clear();
before you write the code posted by Anders Jansson...
Martin
-
November 22nd, 2002, 11:19 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|