Adding ListItem to start of ListBox

A

AndyW

Hi,

I have a listbox which is curerntly getting its source from a dataset:

TListBox.DataSource = dsTemp;

What I would like to do is add a default choice to the start of the
listbox which isn't got from the dataset. I have tried:

TListBox.Items.Add(new ListItem(" All", "Default");
TListBox.DataSource = dsTemp;

But selecting the source afterwards removes it. Is there anyway of
manually adding an entry to the start whilst still getting the rest of
the data from the datasource?

Thanks,
Andy
 
T

Thiruppathi S

HI Andy,

After binding data,
do
TLIstbox.items.insert method to insert a record at a position

Rgds,
Thiruppathi S
 
B

Barry

Andy,
To insert the item:
TListBox.Items.Insert(0, "")

To Preselect the item:
TListBox.SelectedIndex = 0

As previously stated, do this after databinding.

Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top