473,395 Members | 1,941 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,395 software developers and data experts.

listbox control operations

Hi,

I am traversing a list box and comparing its entries
with a string. I am not able to find a method that
allows me to use the current index to retrieve the value.
can you help? here is what I got

if ( listBox1.Items.Count > 0 )

{

for (int x = 1; x <= listBox1.Items.Count ; x++)

{

if ( listBox1.GetItemText(x)== textBox1.Text ) //does not
work..

MessageBox.Show("found "+textBox1.Text);

else

listBox1.Items.Add("Item " +
x.ToString());

}

}

else

listBox1.Items.Add(textBox1.Text);

Thanks
Nov 16 '05 #1
3 4037
if ( listBox1.Items[x].ToString() == textBox1.Text)

"Carlos" <ch******@yahoo.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Hi,

I am traversing a list box and comparing its entries
with a string. I am not able to find a method that
allows me to use the current index to retrieve the value.
can you help? here is what I got

if ( listBox1.Items.Count > 0 )

{

for (int x = 1; x <= listBox1.Items.Count ; x++)

{

if ( listBox1.GetItemText(x)== textBox1.Text ) //does not
work..

MessageBox.Show("found "+textBox1.Text);

else

listBox1.Items.Add("Item " +
x.ToString());

}

}

else

listBox1.Items.Add(textBox1.Text);

Thanks

Nov 16 '05 #2
Thanks scott, I already tried that but it gives me an argument outof range
exception. the x index is valid though... (1) at the time of testing...

"Scott B (Was New Guy)" <se******@hotmail.com> wrote in message
news:O2*************@TK2MSFTNGP10.phx.gbl...
if ( listBox1.Items[x].ToString() == textBox1.Text)

"Carlos" <ch******@yahoo.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Hi,

I am traversing a list box and comparing its entries
with a string. I am not able to find a method that
allows me to use the current index to retrieve the value.
can you help? here is what I got

if ( listBox1.Items.Count > 0 )

{

for (int x = 1; x <= listBox1.Items.Count ; x++)

{

if ( listBox1.GetItemText(x)== textBox1.Text ) //does not work..

MessageBox.Show("found "+textBox1.Text);

else

listBox1.Items.Add("Item " +
x.ToString());

}

}

else

listBox1.Items.Add(textBox1.Text);

Thanks


Nov 16 '05 #3
never mind, the subscript should be one less.
Thanks, I know C, C++, but wait did they change that
in C#?..no they did not.

"Carlos" <ch******@yahoo.com> wrote in message
news:ea**************@TK2MSFTNGP15.phx.gbl...
Thanks scott, I already tried that but it gives me an argument outof range
exception. the x index is valid though... (1) at the time of testing...

"Scott B (Was New Guy)" <se******@hotmail.com> wrote in message
news:O2*************@TK2MSFTNGP10.phx.gbl...
if ( listBox1.Items[x].ToString() == textBox1.Text)

"Carlos" <ch******@yahoo.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Hi,

I am traversing a list box and comparing its entries
with a string. I am not able to find a method that
allows me to use the current index to retrieve the value.
can you help? here is what I got

if ( listBox1.Items.Count > 0 )

{

for (int x = 1; x <= listBox1.Items.Count ; x++)

{

if ( listBox1.GetItemText(x)== textBox1.Text ) //does not work..

MessageBox.Show("found "+textBox1.Text);
else

listBox1.Items.Add("Item " +
x.ToString());

}

}

else

listBox1.Items.Add(textBox1.Text);

Thanks



Nov 16 '05 #4

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

Similar topics

2
by: Luca | last post by:
Hello, I'm using a windows form in which there is a standard ListBox control. I want to add/remove objects from the ArrayList associated to the ListBox, and I want the ListBox immediately shows...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
5
by: dan heskett | last post by:
I'd like to modify the standard .net list box to allow in place editing of the data. I am owner drawing a complex listbox item, but first off, is this even advisable? I have a simple list and...
3
by: Hugh O | last post by:
Hi, There is a ROW property on the Web Listbox control within VB.Net. The description states it is "The number of visible rows to display". I have tried setting this property in many different...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
4
by: Anil Gupte | last post by:
I am using the following code: URLListBox.BeginUpdate() URLListBox.DataSource = DSContent '.Tables("ContentSites") URLListBox.DisplayMember = "ContentSites.SiteName" URLListBox.ValueMember =...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.