sql - ComboBox not showing DisplayMember -


i'm trying display question id's in combo box, in order reproduce matching question in text box. rather question id's appearing, receiving 5 question id's:

wcinterface.ucquestions+questionwcinterface.ucquestions+question

my code:

private loaded boolean = false  private sub ucquestions_load(byval sender system.object, byval e system.eventargs) handles mybase.load      cmbquestion.displaymember = "question_id"     cmbquestion.valuemember = "question_id"     cmbquestion.datasource = retrievequestions() 'when form loads      loaded = true  end sub  private sub cmbquestion_selectedindexchanged(byval sender system.object, byval e system.eventargs) handles cmbquestion.selectedindexchanged     if (loaded)          cmbquestion.displaymember = "question_id"         cmbquestion.valuemember = "question_id"         cmbquestion.datasource = nothing 'resets data source         cmbquestion.datasource = retrievequestions() 'when form loads     end if end sub  public function retrievequestions() list(of question)      dim typelist new list(of question)     dim str string = "select question_id, question_text question"     try         using conn new sqlclient.sqlconnection(dbconnection)             conn.open()             using cmdquery new sqlclient.sqlcommand(str, conn)                 using drresult sqlclient.sqldatareader = cmdquery.executereader()                     while drresult.read                         typelist.add(new question(drresult("question_id"), drresult("question_text")))                     end while                 end using 'automatically closes connection             end using         end using      catch ex exception          msgbox("question list exception: " & ex.message & vbnewline & str)      end try      return typelist  end function 

i'd appreciate suggestions how display question id's, thankyou

you didn't post question class, displaymember , valuemember fields aren't matching property fields in question class:

it should this:

public class question   property questionid integer   property questiontext string    public sub new(q_id integer, q_text string)     questionid = q_id     questiontext = q_text   end sub end class 

then data source properties this:

cmbquestion.displaymember = "questionid" cmbquestion.valuemember = "questionid" cmbquestion.datasource = retrievequestions()  

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -