Click here to Skip to main content
15,790,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a listbox in form 1, when the 'next' button is clicked I want the first item in the listbox to become the title (text in the label) in form 2.

Is it possible to do this? I've written some code...
Ops.PgeTitleLbl.Text = CustLB.GetItemText(CustLB.SelectedItem);

This only works if an item in the listbox is selected, I want it to work without needed to select an item

What I have tried:

Operations Ops = new Operations();
Ops.PgeTitleLbl.Text = CustLB.SelectedItem.ToString;
Updated 22-Mar-18 11:36am
Richard MacCutchan 22-Mar-18 13:23pm    
And did it work?
Member 13512434 22-Mar-18 13:33pm    

Try this:
Ops.PgeTitleLbl.Text = CustLB.GetItemText(CustLB.SelectedItem);
You should also check if SelectedItem is not null.

If it won't work, try the example here: ListBox.SelectedItem Property (System.Windows.Forms)[^]
Share this answer
Check this: Changing label text using listbox[^]

Note: never repost again! Rather than it, please, update your question (use Improve question[^] widget on the right-bottom corner of your question) or post a comment (by using "Have a Question or Comment" widget).
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900