当前位置:网站首页>WPF 数据绑定(四)
WPF 数据绑定(四)
2022-06-11 06:48:00 【flysh05】
实现绑定到DataSet对象。
界面设计:
<ListBox x:Name="listProducts" Margin="5" DisplayMemberPath="ModelName" />
同样创建Grid的绑定,指定到列表元素,选择的Item
<Grid DataContext="{Binding ElementName=listProducts, Path=SelectedItem}" >
后台代码:
(1) 定义一个全局的变量
private DataTable products;
(2) 从数据库获取数据,赋值个定义的全局变量后,绑定到UI列表
products= App.StoreDbDataSet.GetProducts();
listProducts.ItemsSource= products.DefaultView;
实际取得DataSet 的默认DataTable视图,绑定到列表的ItemSource
因为数据源以DataTabel的方式展示,可以删除其中的行:
((DataRowView)listProducts.SelectedItem).Row.Delete();
将选择的对象强转为DataRowView,这样就可以使用Row属性的Delete方法删除
效果如下:

边栏推荐
- Communication between different VLANs
- Oracle prompt invalid number
- What are the differences and usages of break and continue?
- 563. slope of binary tree
- Multimedia框架解析之MediaExtractor源码分析(一)
- 021-MongoDB数据库从入门到放弃
- 关于 QtCreator的设计器QtDesigner完全无法正常拽托控件 的解决方法
- 关于SIoU的原理和代码实现(回顾IoU、GIoU、DIoU、CIoU)
- SQL语言-查询语句
- What is sentinel produced by Ali?
猜你喜欢

Differences between FindIndex and indexof

Who is stronger, zip or 7-Zip, and how to choose?

client-go gin的简单整合六-list-watch二(关于Rs与Pod以及Deployment的完善)

Starting from scratch (V) realize bullet positioning and animation

Handwritten a message queue in two ways

572. subtree of another tree

NPM upgrade: unable to load file c:\users\administrator\appdata\roaming\npm\npm-upgrade ps1

Scripy web crawler series tutorials (I) | construction of scripy crawler framework development environment

Multimedia框架解析之MediaExtractor源码分析(一)

Use of qscriptengine class
随机推荐
arguments......
How exactly does instanceof judge the reference data type!
3.1 测试函数的命名规则
Dynamic import
A piece of code has been refactored six times by the boss, and my mind is broken
开源漫画服务器Mango
Array information management system reconfiguration preheating (1) how to write basic logic using linear continuous structure?
Illustrate the principle of one-way linked list and the method of JS to realize linked list [with source code]
Learn a trick to use MySQL functions to realize data desensitization
News web page display
Redux learning (III) -- using Redux saga, writing middleware functions, and splitting reducer files
六月集训(第11天) —— 矩阵
socket. IO cross domain stepping pit
Summary of string processing skills III
Vulhub 8.1-backdoor vulnerability recurrence
Why don't we have our own programming language?
Starting from scratch (V) realize bullet positioning and animation
Handwriting promise [03] - realize multiple calls and chain calls of then method
【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】
Stack -- one of two common linear structures of linear structure