Jump to content

Getting string from selected listbox item

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Cushpajz

Cushpajz

    Newbie

  • Members
  • PipPipPip
  • 30 posts
  • Location:Novi Sad
  • Programming Language:C#
  • Learning:C, C++, C#, PHP
This is maybe a simple question but i need to know how to get string from selected listbox item, can anyone help me?

#2
Gerg? Magyar

Gerg? Magyar

    Newbie

  • Members
  • PipPip
  • 22 posts

[B][COLOR="#0000FF"]private void[/COLOR][/B] listBox1_SelectedIndexChanged(object sender, [COLOR="#0000FF"][B]System.EventArgs[/B][/COLOR] e)

{

   MessageBox.[B][COLOR="#0000FF"]Show[/COLOR][/B](([B][COLOR="#0000FF"]string[/COLOR][/B])listBox1.[COLOR="#0000FF"][B]SelectedItem[/B][/COLOR]);

}




#3
Cushpajz

Cushpajz

    Newbie

  • Members
  • PipPipPip
  • 30 posts
  • Location:Novi Sad
  • Programming Language:C#
  • Learning:C, C++, C#, PHP
Not in messagebox, I want to put it to some string, example: string a = listBox1....

#4
Gerg? Magyar

Gerg? Magyar

    Newbie

  • Members
  • PipPip
  • 22 posts

[COLOR="#0000FF"][B]public[/B][/COLOR] [COLOR="#0000FF"][B]string[/B][/COLOR] a = '';


[COLOR="#0000FF"][B]private[/B][/COLOR][COLOR="#0000FF"][B] void[/B][/COLOR] listBox1_SelectedIndexChanged(object sender, [B][COLOR="#0000FF"]System.EventArgs[/COLOR][/B] e)

{

   a = ([COLOR="#0000FF"][B]string[/B][/COLOR])listBox1.[B][COLOR="#0000FF"]SelectedItem[/COLOR][/B];

}




#5
Cushpajz

Cushpajz

    Newbie

  • Members
  • PipPipPip
  • 30 posts
  • Location:Novi Sad
  • Programming Language:C#
  • Learning:C, C++, C#, PHP

Gerg? Magyar said:


[COLOR="#0000FF"][B]public[/B][/COLOR] [COLOR="#0000FF"][B]string[/B][/COLOR] a = '';


[COLOR="#0000FF"][B]private[/B][/COLOR][COLOR="#0000FF"][B] void[/B][/COLOR] listBox1_SelectedIndexChanged(object sender, [B][COLOR="#0000FF"]System.EventArgs[/COLOR][/B] e)

{

   a = ([COLOR="#0000FF"][B]string[/B][/COLOR])listBox1.[B][COLOR="#0000FF"]SelectedItem[/COLOR][/B];

}


thanks it works! :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users