开发者

Combobox selected value return DataRowView

I set combobox.datasource to a dataview item (so that it binds to a table), When I get return value from combobox.selectedvalue. Error was returned bcos it is of type "system.data.datarowview"

I don't know why commonly its return value as text

The code :

 If ldstList.Tables(0).Rows.开发者_开发百科Count <> 0 Then
                        With CbStatus
                            .DataSource = ldstList.Tables(0)
                            .DisplayMember = "CardStatus"
                            .ValueMember = "StatusID"
                        End With
                    End If

If Integer.Parse(CbStatus.SelectedValue) > 0 Then
    GridLoad(Integer.Parse(CbStatus.SelectedValue))
End If


Regardless of other issues or solutions, please make sure you set the properties of the ComboBox in the right order:

.DisplayMember = ...;
.ValueMember = ...;
.DataSource = ....;  // Notice how this one is last?

Setting the DataSource property first will lead to "system.data.datarowview" issues.


You're not binding to the DataView, you're binding to the DataTable itself. The DefaultView property returns a DataView you can use:

  CbStatus.DataSource = ldstList.Tables(0).DefaultView


I don't know why the issue arises. But I have found a solution:

If Integer.Parse(DirectCast(CbStatus.SelectedItem, DataRowView).Item("StatusID")) > 0 Then
  GridLoad(Integer.Parse(DirectCast(CbStatus.SelectedItem, DataRowView).Item("StatusID")))
End If

Thanks to those who answered, and please do post an explanation or a better solution if you have one.


On the Combobox or dropdown properties go to the databindings property...select advanced...select text or selected value or selectedItem depending on which property you want to set and then click the binding dropdownlist on the top right of the same screen, select the name of the column you want to return for display and after doing that select the format of the data on the format type listbox (numeric,currency,datetime,etc) and then click OK. This is assuming that you did set your value member and display member properties on your combobox or dropdown and this is also assuming that you are not binding via code but through the datasource property of your control (dropdown/combobox)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜