以编程方式设置datagrid itemssource模式 [英] Set datagrid itemssource mode programmatically

查看:82
本文介绍了以编程方式设置datagrid itemssource模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想知道你是否可以帮助我。我正在尝试转换



Hello all,

I was wondering if you could help me out. I am trying to convert

<DataGrid x:Name="testdatagrid" ItemsSource="{Binding TestDataVM, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" AutoGenerateColumns="True" Margin="0,0,429,146"/>





和set我的testdatagrid的itemssource以编程方式提供给数据集,以便能够在单击按钮时在表之间切换。



我已设法使用以下代码设置itemssource :



and set the itemssource of my testdatagrid programmatically to a dataset to be able to switch between tables on the click of a button.

I have managed to set the itemssource with the following code:

testdatagrid.Itemssource = TestDataVM.TestDataset.Tables("test").defaultview





但是我想将模式设置为twoway以自动刷新数据网格并且还将Updatesourcetrigger设置为属性已更改。



我找不到我在网上寻找的内容。我尝试创建一个新的绑定并设置模式和updatesourcetrigger



but I would like to set the mode to twoway to have the datagrid refresh automatically and also set the Updatesourcetrigger to property changed.

I could not find what I was looking for online. I tried creating a new binding and setting the mode and updatesourcetrigger

Dim b as New Binding
b.mode = mode.twoway
....
testdatagrid.setbinding(testdatagrid.Itemssource, b)



但这不起作用。这里有没有人知道如何以编程方式设置模式和sourcetrigger?也许我在这里做了一些根本错误的事情?


but that did not work. Does anyone here have an idea of how I could set the mode and sourcetrigger programmatically? Maybe I am doing something fundamentally wrong here?

推荐答案

首先如果你使用绑定,那么你只需要改变的值ViewModel中的TestDataVM 到你想要显示的内容。你正在做的是直接设置数据源,这意味着你没有使用绑定,所以绑定当然不起作用。如果要以编程方式设置绑定: http://stackoverflow.com/questions/6988273/wpf-binding-programatically [ ^ ]
First of all if you are using binding, then you just have to change the value of TestDataVM in the ViewModel to what you want to display. What you are doing is setting the datasource directly, and that means you are not using binding, so of course the binding will not work. If you want to programatically set the binding: http://stackoverflow.com/questions/6988273/wpf-binding-programatically[^]


这篇关于以编程方式设置datagrid itemssource模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆