Difference between SelectedItem, SelectedValue and SelectedValuePath

后端 未结 5 805
轻奢々
轻奢々 2020-11-22 01:20

What is the difference betweeen the following:

  • SelectedItem
  • SelectedValue
  • SelectedValuePath

All these dependency properties ar

5条回答
  •  醉话见心
    2020-11-22 01:36

    Every control that uses Collections to store data have SelectedValue, SelectedItem property. Examples of these controls are ListBox, Dropdown, RadioButtonList, CheckBoxList.

    To be more specific if you literally want to retrieve Text of Selected Item then you can write:

    ListBox1.SelectedItem.Text;
    

    Your ListBox1 can also return Text using SelectedValue property if value has set to that before. But above is more effective way to get text.

    Now, the value is something that is not visible to user but it is used mostly to store in database. We don't insert Text of ListBox1, however we can insert it also, but we used to insert value of selected item. To get value we can use

    ListBox1.SelectedValue
    

    Source

提交回复
热议问题