Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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"/>


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:
VB
testdatagrid.Itemssource = TestDataVM.TestDataset.Tables("test").defaultview


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
VB
Dim b as New Binding
b.mode = mode.twoway
....
testdatagrid.setbinding(testdatagrid.Itemssource, b)

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?
Posted
Comments
noblepaulaziz 11-Dec-13 19:15pm    
Are you sure it is ItemSource property and not DataSource property you want to set programmatically?

I have not come across such property as itemsource property for DataGridView.

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900