Click here to Skip to main content
15,885,365 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.Show();
Ops.PgeTitleLbl.Text = CustLB.SelectedItem.ToString;
Posted
Updated 22-Mar-18 10:36am
v3
Comments
Richard MacCutchan 22-Mar-18 13:23pm    
And did it work?
Member 13512434 22-Mar-18 13:33pm    
no

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
 
v3
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