|
-
May 17th, 2011, 04:03 AM
#1
How to get value...
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
-
May 17th, 2011, 07:58 AM
#2
Re: How to get value...
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.
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
-
May 17th, 2011, 10:52 AM
#3
Re: How to get value...
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:
Code:
string text1 = listbox1.Text
If problems persist, please provide more information on the error your are encountering.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
May 17th, 2011, 11:41 PM
#4
Re: How to get value...
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?
-
May 18th, 2011, 10:44 AM
#5
-
May 18th, 2011, 12:34 PM
#6
Re: How to get value...
I believe he/she wants the selected item from the list box.
In that case you need to do the following...
Code:
textBox1.Text = listBox1.SelectedItem.ToString();
string s = listBox1.SelectedItem.ToString();
This will return the string value of the selected item from the list box.
Or you could cast from an object to a string...
Code:
textBox1.Text = (string)listBox1.SelectedItem;
Last edited by user612345; May 18th, 2011 at 12:37 PM.
-
May 18th, 2011, 11:31 PM
#7
Re: How to get value...
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."
 Originally Posted by user612345
I believe he/she wants the selected item from the list box.
In that case you need to do the following...
Code:
textBox1.Text = listBox1.SelectedItem.ToString();
string s = listBox1.SelectedItem.ToString();
This will return the string value of the selected item from the list box.
Or you could cast from an object to a string...
Code:
textBox1.Text = (string)listBox1.SelectedItem;
-
May 19th, 2011, 07:56 AM
#8
Re: How to get value...
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|