Microsoft Developer Network > Página Inicial dos Fóruns > Visual C# General > Would like to include a combobox in a loop (same combobox is used several times in a survey)
Fazer uma PerguntaFazer uma Pergunta
 

RespondidoWould like to include a combobox in a loop (same combobox is used several times in a survey)

  • quarta-feira, 4 de novembro de 2009 17:31jclark89 Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    I am attempting to write a survey in C# and would like to add a combobox to a loop.  The combobox is used several times in the survey, and rather than include the box several times would like to add that to a method that could be called, the item selected and the value from the selection returned to the calling question.

    My question is this:
    1.  How can I access the value of the combobox once a selection has been made?  I have tried using selected.Index, but have not had any success with it.

    Thank  you for any replies.

Respostas

  • quarta-feira, 4 de novembro de 2009 17:54Rudedog2ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    Depending upon how you fill the combobox, and what you info you need back you want to use one of the .....

    ComboBox .SelectedXXXX

    .... properties.  There are 3 of them. 

    SelectedItem
    SelectedText
    SelectedValue

    IntelliSense should make them appear for you as you type. 
    Change the Bold text to the name of your combobox instance.

    In many cases, just getting the SelectedText is easiest.
    The other properties return System.Objects that represent that actual item itself.
    Mark the best replies as answers. "Fooling computers since 1971."

Todas as Respostas

  • quarta-feira, 4 de novembro de 2009 17:54Rudedog2ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    Depending upon how you fill the combobox, and what you info you need back you want to use one of the .....

    ComboBox .SelectedXXXX

    .... properties.  There are 3 of them. 

    SelectedItem
    SelectedText
    SelectedValue

    IntelliSense should make them appear for you as you type. 
    Change the Bold text to the name of your combobox instance.

    In many cases, just getting the SelectedText is easiest.
    The other properties return System.Objects that represent that actual item itself.
    Mark the best replies as answers. "Fooling computers since 1971."