PC Review


Reply
Thread Tools Rate Thread

Adding Items to a Listbox on a Windows form

 
 
=?Utf-8?B?Sm9obiBSLg==?=
Guest
Posts: n/a
 
      30th Dec 2004
How do I create an item for a listbox?

I want to do something like this EXCEPT for a listbox:

ListViewItem item = new ListViewItem();
item.Text = column.Name;
int height = item.Bounds.Height;
listView1.Items.Add(item);

I want to use the item's properties for something else.

What's the syntax look like for instantiating an item for a listbox?

 
Reply With Quote
 
 
 
 
Jeff Gaines
Guest
Posts: n/a
 
      30th Dec 2004
On 30/12/2004 John R. wrote:

> How do I create an item for a listbox?
>
> I want to do something like this EXCEPT for a listbox:
>
> ListViewItem item = new ListViewItem();
> item.Text = column.Name;
> int height = item.Bounds.Height;
> listView1.Items.Add(item);
>
> I want to use the item's properties for something else.
>
> What's the syntax look like for instantiating an item for a listbox?


A ListBox is a bit more simple than a ListView so it's just:

listBox1.Items.Add(Item);

Item can be any object so either just a string or, if you want more
data availble when an item is clicked, you can add an instance of a
class.

e.g. if you had a Class called cListData that contained say a string
called Name, a number called RecordNumber etc. set up an instance of
the class (say cldTemp), set up the data you want and then do:

listBox1.Items.Add(cldTemp);

If you do this you may want to over ride the string property of the
class to return whatever makes most sense to show in the ListBox e.g.

// Override ToString method so that Name is default
public override string ToString()
{
return this.Name;
}



--
Jeff Gaines
Posted with XanaNews 1.17.1.2 http://www.wilsonc.demon.co.uk/delphi.htm
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding items in listbox =?Utf-8?B?TWFobW91ZCBTaGFiYW4=?= Microsoft C# .NET 2 22nd Nov 2007 10:00 AM
Adding Items to a ListBox-Unique Items Only jpendegraft Microsoft Excel Programming 2 2nd May 2004 02:27 AM
Adding items to a spreadsheet from a user form listbox aet-inc Microsoft Excel Programming 1 3rd Dec 2003 05:13 AM
Re: Mutiple windows for same form and adding items in lists jfp Microsoft Access Form Coding 0 9th Sep 2003 05:28 PM
Re: Mutiple windows for same form and adding items in lists Albert D. Kallal Microsoft Access Form Coding 1 7th Sep 2003 02:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:33 AM.