当前位置:网站首页>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方法删除
效果如下:

边栏推荐
- Resolve typeerror: ctx injections. tableRoot.$ scopedSlots[ctx.props.column.slot] is not a function
- 572. 另一个树的子树
- A highly controversial issue
- 无心剑汉英双语诗001.《爱》
- Redux learning (II) -- encapsulating the connect function
- 网狐游戏服务器房间配置约战定制功能实现
- What are the differences and usages of break and continue?
- Communication between different VLANs
- fatal: refusing to merge unrelated histories
- Starting from scratch (V) realize bullet positioning and animation
猜你喜欢

JVM from getting started to giving up 2: garbage collection

A piece of code has been refactored six times by the boss, and my mind is broken

【Matlab WSN通信】A_Star改进LEACH多跳传输协议【含源码 487期】
![[]==![]](/img/65/ab724c74b080da319ed5c01c93fdb7.png)
[]==![]

Differences between FindIndex and indexof

Why don't we have our own programming language?

Open source cartoon server mango

UEFI finding PCI devices

617. 合并二叉树

Warning: Each child in a list should have a unique “key“ prop.
随机推荐
统计某次操作(函数)耗时时长
核查医药代表备案信息是否正确
Open source cartoon server mango
Exchange two values without introducing the third variable
数组去重。。。。
Jenkins user rights management
Sentinel annotation support - @sentinelresource usage details
Oracle提示无效数字
数学方法论的含义和研究意义
Practice: how to reasonably design functions to solve practical problems in software development (I)
VTK-vtkPlane和vtkCutter使用
Mediaextractor source code analysis of multimedia framework analysis (1)
Redux learning (I) -- the process of using Redux
How to make time planning
Aircraft war from scratch (II) simple development
Flutter Container组件
3.1 测试函数的命名规则
动态import
Detailed explanation of mutual call between C language and Lua
617. 合并二叉树