(Felix Wu [MS])
11/25/2002 11:34:00 AM
Hi Yawen,
"listBox_A.SelectedItem = "xxx"; " does not work because the SelectedItem
property is designed for setting the currently selected item in the
ListBox. The set_SelectedItem method calls the
ObjectCollection::IndexOf(object) method to get the index of the object you
specified on the right side of the "=" operator. In your case, it is a
string object with the text of "xxx". If a matching object is found in the
ListBox's ObjectCollection, the set_SelectedIndex method will be called
with the returned Index to set the found object to be the current item. If
no matching object is found, the set_SelectedItem method just returns.
This is why nothing happens when you call "listBox_A.SelectedItem = "xxx";
To modify the selected item text, use this method instead:
listBox1.Items[listBox1.SelectedIndex]="New Text";
Hope this helps.
Regards,
Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Yawen Chan" <y3chan@engmail.uwaterloo.ca>
>Subject: Editing an listbox item
>Date: Thu, 21 Nov 2002 15:59:34 +0800
>Lines: 17
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Message-ID: <ucyArPTkCHA.716@tkmsftngp11>
>Newsgroups:
microsoft.public.dotnet.framework.sdk,microsoft.public.dotnet.framework.wind
owsforms,microsoft.public.dotnet.framework.windowsforms.controls
>NNTP-Posting-Host: 147.8.183.244
>Path: cpmsftngxa08!tkmsftngp01!tkmsftngp11
>Xref: cpmsftngxa08 microsoft.public.dotnet.framework.windowsforms:34033
microsoft.public.dotnet.framework.windowsforms.controls:3960
microsoft.public.dotnet.framework.sdk:4917
>X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
>
>(C#)
>I added items to a listbox using:
>
>listBox_A.Items.Add("Item1");
>
>Then I want to edit the item's string to something else, so I did
>
>listBox_A.SelectedItem = "xxx";
>
>But the item didn't work. The listbox item was still "Item1", but not
>"xxx". Why is that?
>
>Thanks a lot.
>
>Yawen
>
>
>