Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Listbox items text and text boxes?
#1
Ok, I have I have a list box, kryptonListBox1, and a text box textBoxX1. I want to get the selected item in the listbox's text into the text box. My code is:

textBoxX1.Text = kryptonListBox1.SelectedItem.ToString

I've tried using .Text.ToString, but with both I get the error 'Object reference not set to instance of an object'

What am I doing wrong and what's the easiest way to fix it?
#2
Also, to clear something up, when it's using .Text.ToString, it says 'Object variable or With block variable not set'
#3
The code you are using should work fine but just in case try with the code below:

[code2=vbnet]TextBox1.Text = KryptonListBox1.SelectedItems.Item(0).ToString[/code2]

Try using break points and trace the error because the problem is not with the code you're using. Also try to use a try/catch block and see if that corects the problem by ignoring it.

For further help please provide more info like what kind off error it is , where exactly are you using the code and so on..
Sssssssssoftware developer...
#4
As Snake_eyes suggested (Thanks!), this code should definitely work. The error may be appearing due to the fact that a valid item is not actually being selected. You can try to make sure an item is being selected by checking first, like so:
[code2=vbnet]If Not (kryptonListBox1.SelectedItem Is Nothing) Then
textBoxX1.Text = kryptonListBox1.SelectedItem.ToString
End If[/code2]
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Text to Speech Vinwarez 2 11,680 03-13-2012, 10:56 PM
Last Post: Vinwarez
  Files in a listbox Hurricane 4 19,775 02-27-2012, 03:32 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)