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

listbox."want to check a item during fetching"

In a desktop application C#,I have a list box.there are multiple approximate 7 items,& i have to checked the 4th item in the list box initially ,How can i do that?
Jun 2 '11 #1
1 1094
Frinavale
9,735 Expert Mod 8TB
If you check out the MSDN article for the ListBox there is some nice sample code that demonstrates how to select items in the control.

The following is the sample code posted in that article:

Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, System.EventArgs e)
  2. {
  3.    // Create an instance of the ListBox.
  4.    ListBox listBox1 = new ListBox();
  5.    // Set the size and location of the ListBox.
  6.    listBox1.Size = new System.Drawing.Size(200, 100);
  7.    listBox1.Location = new System.Drawing.Point(10,10);
  8.    // Add the ListBox to the form.
  9.    this.Controls.Add(listBox1);
  10.    // Set the ListBox to display items in multiple columns.
  11.    listBox1.MultiColumn = true;
  12.    // Set the selection mode to multiple and extended.
  13.    listBox1.SelectionMode = SelectionMode.MultiExtended;
  14.  
  15.    // Shutdown the painting of the ListBox as items are added.
  16.    listBox1.BeginUpdate();
  17.    // Loop through and add 50 items to the ListBox.
  18.    for (int x = 1; x <= 50; x++)
  19.    {
  20.       listBox1.Items.Add("Item " + x.ToString());
  21.    }
  22.    // Allow the ListBox to repaint and display the new items.
  23.    listBox1.EndUpdate();
  24.  
  25.    // Select three items from the ListBox.
  26.    listBox1.SetSelected(1, true);
  27.    listBox1.SetSelected(3, true);
  28.    listBox1.SetSelected(5, true);
  29.  
  30.    // Display the second selected item in the ListBox to the console.
  31.    System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems[1].ToString());
  32.    // Display the index of the first selected item in the ListBox.
  33.    System.Diagnostics.Debug.WriteLine(listBox1.SelectedIndices[0].ToString());             
  34. }
  35.  
  36.  
Jun 3 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JPSutor | last post by:
When I have the user tab over to the listbox control, how can I get one of the selected items to be highlighted without the user manually selecting it. The object is to show a highlighted item...
1
by: Tom Wild | last post by:
Hi I have a listbox on a webform which has Autopostback set to true. When the user selects an item in the listbox and the form reloads, the listbox scrolls to put the selected item as high up...
2
by: Rlrcstr | last post by:
I'm rolling my own with a listbox. The items in the list box are of varying sizes and I'm hit checking when the litbox is checked to see what portion of an item the user has clicked on. Mostly...
2
by: Mr. Bean | last post by:
Hello, How could i change the selected item of a listbox on runtime. I have a dropdownn list with 4 values, when the appplication is initiated the selected item in the listbox is supposed to...
1
by: lkp_ajay_mehta | last post by:
plz help.i am beginner of ms access.any thing about listbox,combobox which help me to understand how to create listbox,combobox for working sent to me.
5
by: yancheng.cheok | last post by:
hello, may i know how i can determine whether a pointer is pointing to an array or a single item during runtime? this is because in certain situation, i need to determine whether to use delete...
1
by: cptkirkh | last post by:
I havea listbox bound to a datatable. When the form loads it thinks the first item is selected. Is there anyway to tell the listbox when it loads not to select the first time automatically?
3
by: is49460 | last post by:
Hello, I have a form with various controls but to simplify the problem let’s say I have 2 listboxes. The selection in listbox1 controls RowSource of the listbox2. For example lstCars contains car...
1
by: pradeep | last post by:
Hi, I want to display Listbox containing check boxes in HTML. How can i do this ? Can you guide me.
8
by: Ratko | last post by:
Say you have something like this: for item in myList: del item Would this actually delete the item from the list or just decrement the reference counter because the item in myList is not...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.