Why I get “System.Data.DataRowView” instead of real values in my Listbox?

前端 未结 12 786
一向
一向 2020-11-29 08:24

I\'m hoping someone can help. But whenever I run my code and try to view a highscore all I get back in my listbox is System.Data.DataRowView.

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 09:26

    I always have to deal with this problem, even if I set the DisplayMember and ValueMembers of the List Box.

    Your current code is correct and should work, if you need access to the current selected item value of any column of your dTable you can get them doing this:

    DataRowView drv = (DataRowView)lstNames.SelectedItem;
    String valueOfItem = drv["NameAndScore"].ToString();
    

    What I like about getting the entire DataRowView is that if you have more columns you can still access their values and do whatever you need with them.

提交回复
热议问题