locked
Combobox:system.data.datarowview error

    Question

  • I have made an application in vb.net that utilizes a sql server database populated combobox.i am able to display the data in the combobox......but whenever i select any value, instead of getting actual value, i gete "system.data.datarowview". what shud i do to avoid this and to get actual values??plz help me in this regard.
    BR 
    OMar_aa
    Wednesday, November 19, 2008 6:49 AM

Answers

  • when you bind data to a combobox, entire datarow is binded to the control, you need to convert selected item to row and get the value

    note: try using, one of those conversion.

    CType(ComboBox1.SelectedItem, DataRow).Item("ElementID")

    or
    CType(ComboBox1.SelectedItem, DataRowView).Item("ElementID")

      Dim selectedvalue As String = CType(ComboBox1.SelectedItem, DataRowView).Item("ElementID")   'replace by value member name

    Arjun Paudel
    • Proposed as answer by konikula Thursday, November 20, 2008 6:16 AM
    • Marked as answer by Xingwei Hu Tuesday, November 25, 2008 6:48 AM
    Wednesday, November 19, 2008 8:18 AM
  • This behaviour (that you obtain whole row, instead single member) can get very usefull, when you are showing e.g. "Name" in combo, but you need to delete by "Id" ... if it simply returned "Name", you would be pretty bussy to find "Id" for it, like this, you are free to select any member, and thus you can consider combobox, to be selecting rows, instead members, more logically.

    Regards, Matej
    This contributor is MSDN testing bot, using BabelFish translator, passive NN "Thread integrator" and Google's VBCContextSearch api to help you resolving threads, if you want to improve it, just react to its posts. Your MSDN team :)
    • Proposed as answer by konikula Sunday, November 23, 2008 12:11 AM
    • Marked as answer by Xingwei Hu Tuesday, November 25, 2008 6:48 AM
    Thursday, November 20, 2008 6:15 AM

All replies

  • when you bind data to a combobox, entire datarow is binded to the control, you need to convert selected item to row and get the value

    note: try using, one of those conversion.

    CType(ComboBox1.SelectedItem, DataRow).Item("ElementID")

    or
    CType(ComboBox1.SelectedItem, DataRowView).Item("ElementID")

      Dim selectedvalue As String = CType(ComboBox1.SelectedItem, DataRowView).Item("ElementID")   'replace by value member name

    Arjun Paudel
    • Proposed as answer by konikula Thursday, November 20, 2008 6:16 AM
    • Marked as answer by Xingwei Hu Tuesday, November 25, 2008 6:48 AM
    Wednesday, November 19, 2008 8:18 AM
  • This behaviour (that you obtain whole row, instead single member) can get very usefull, when you are showing e.g. "Name" in combo, but you need to delete by "Id" ... if it simply returned "Name", you would be pretty bussy to find "Id" for it, like this, you are free to select any member, and thus you can consider combobox, to be selecting rows, instead members, more logically.

    Regards, Matej
    This contributor is MSDN testing bot, using BabelFish translator, passive NN "Thread integrator" and Google's VBCContextSearch api to help you resolving threads, if you want to improve it, just react to its posts. Your MSDN team :)
    • Proposed as answer by konikula Sunday, November 23, 2008 12:11 AM
    • Marked as answer by Xingwei Hu Tuesday, November 25, 2008 6:48 AM
    Thursday, November 20, 2008 6:15 AM