Q1)How to get the current value from a listbox? (for e.g name of listbox is listbox1)
I am trying text1=tlistbox1.text .........but it gives error
Printable View
Q1)How to get the current value from a listbox? (for e.g name of listbox is listbox1)
I am trying text1=tlistbox1.text .........but it gives error
Welcome to the forum. You need to give us specific details about your problems- if you reference an error we need to know the exact contents of the error message. Otherwise we probably won't be able to help.
Hi and welcome,
You can always use MSDN to look up documentation on elements of the C# library. In particular, this link should be useful:
http://msdn.microsoft.com/en-us/libr...tbox.text.aspx
As you typed it, it looks like perhaps you are not paying close attention to case and spelling (both of which matter). Try:
If problems persist, please provide more information on the error your are encountering.Code:string text1 = listbox1.Text
I am trying...
string sh1=sh2=sh3= null;
sh1="may month" ;
sh2 = listBox1.Text;
sh3=sh1 +"Year is is:"+sh2;
but I am not getting the value from sh2(listbox value). Also, by default value from the listbox is string type or value type?
I think somewhere on that page can help you.
http://www.homeandlearn.co.uk/csharp/csharp_s3p7.html
I believe he/she wants the selected item from the list box.
In that case you need to do the following...
This will return the string value of the selected item from the list box.Code:textBox1.Text = listBox1.SelectedItem.ToString();
string s = listBox1.SelectedItem.ToString();
Or you could cast from an object to a string...
Code:textBox1.Text = (string)listBox1.SelectedItem;
Hi,
Thanks, this works , but the restriction is that the value from the listbox should be highlited,
otherwise (if simply scrolled and selected, not highlited in this case) it gives exception error that,...
" Null Refernce Exeption was unhandled
Object refernce was not set to an instanceof an object."
Are you trying to send multiple items over to a string? Like if you select more then one item in the listbox because that can lead you to a null reference.
I think you need to provide more information what exactly you are trying achieve. I know you want the value from a listbox but you might be hitting conditions that a simple ToString or Cast wont solve.