c# - ComboBox SelectedValue Returning an Object And Not The Value -
goal: when form loads doing database phone call returning me datatable want assign keyvaluepair(string,string) datasource combo-box. display fellow member beingness key (railcarid) , value fellow member beingness value (railcartransaction_guid)(i storing string).
the problem having, when combobox.selectedvalue...it returning me object rather string. can suggest doing wrong here?
i using dictionary (and error out), , thru searching resolve issue ended using bindinglist. combobox on application displays object array in display. below, code snippets:
private void getalltransactions() { bindinglist<keyvaluepair<string, string>> transactions = new bindinglist<keyvaluepair<string, string>>(); string sql = "select * railcartransaction iscomplete = 'true' , isuploaded = 'false'"; datatable transactions = session1.getrecords(sql); (int = 0; < transactions.rows.count; i++) { transactions.add(new keyvaluepair<string, string>(transactions.rows[i]["railcarid"].tostring(), transactions.rows[i]["railcartransaction_guid"].tostring())); } cboxrailcars.displaymember = "key"; cboxrailcars.valuemember = "value"; cboxrailcars.datasource = transactions; }
since combobox.valuemember
set property of any info type (it int
or datetime
example, not string
), selectedvalue
property object.
you have know type you're dealing , convert back:
var selectedrailcar = convert.tostring(cboxrailcars.selectedvalue);
c# winforms visual-studio-2008 combobox windows-ce
No comments:
Post a Comment