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

边栏推荐
- During unity panoramic roaming, AWSD is used to control lens movement, EQ is used to control lens lifting, and the right mouse button is used to control lens rotation.
- Handwritten a message queue in two ways
- 【迅为干货】龙芯2k1000开发板opencv 测试
- 解决ffmpeg获取AAC音频文件duration不准
- Stack -- one of two common linear structures of linear structure
- [turn] flying clouds_ Qt development experience
- 关于SIoU的原理和代码实现(回顾IoU、GIoU、DIoU、CIoU)
- Oracle prompt invalid number
- Check whether the filing information of the medical representative is correct
- Learn a trick to use MySQL functions to realize data desensitization
猜你喜欢

Detailed explanation of mutual call between C language and Lua

Unity 全景漫游过程中使用AWSD控制镜头移动,EQ控制镜头升降,鼠标右键控制镜头旋转。

MongoDB安装
![JS implementation of graphic merging and sorting process [source code attached]](/img/c8/210ddab791eb2319519496f7c7d010.jpg)
JS implementation of graphic merging and sorting process [source code attached]

About the designer of qtcreator the solution to the problem that qtdesigner can't pull and hold controls normally
![JS implementation of Hill sort of graphic insertion sort [with source code]](/img/5a/b89fd5a0ebbc7ca17cc3e1fcb37c8f.jpg)
JS implementation of Hill sort of graphic insertion sort [with source code]

Check whether the filing information of the medical representative is correct

The realization of online Fox game server room configuration battle engagement customization function

Why don't we have our own programming language?

The nearest common ancestor of 235 binary search tree
随机推荐
Multimedia框架解析之MediaExtractor源码分析(一)
22年五月毕设
Why don't we have our own programming language?
Throttling and anti shake
争议很大的问题
How exactly does instanceof judge the reference data type!
Lazy load
Reconstruction and preheating of linked list information management system (2) how to write the basic logic using linear discontinuous structure?
Warning: Each child in a list should have a unique “key“ prop.
Detailed explanation of mutual call between C language and Lua
Handwritten promise [05] - exception capture of promise method and optional parameters of then method implementation
Training and testing of super score model in mmediting
617. 合并二叉树
Quick sorting of graphic array [with source code]
Text overflow failure
What are the differences and usages of break and continue?
arguments......
通过两种方式手写一个消息队列
双周投融报:资本抢滩元宇宙游戏
Alias the path with the help of craco