I have a DataGrid
bind to a database with one Table and one Column (FooTable and FooName).
With my following code, I can bind DataGrid
to Dat
Try calling dt.DataBind();
at the end.
Hi i edit my answer in your other thread .
the general way i use when working with datatables, datagrid and wpf/mvvm:
i always bind the datagrid itemssource to the BindingListCollectionView of the datatable. i do this because i can easily filter, refresh or add/delete/modify the datatable items.
pls post your xaml or cs code where you bind the Itemssource.
does your DataSet_Add_Click add the row to your datatable? if yes then it seems is just a refresh/binding problem with your datagrid.
when i work with datatables and datagrid i always use the following
//ctor or init
dt = ds.Tables["FooTable"];
//the next line you have to write after you initialize your datatable
this.MyView = (BindingListCollectionView)CollectionViewSource.GetDefaultView(this.dt);
XAML
<DataGrid ItemsSource="{Binding MyView }"/>
Refresh
this.MyView.Refresh();
EDIT: MyView is a property
public BindingListCollectionView MyView
{
get {return this._myview;}
set {this._myview = value; OnPropertyChanged("MyView");
}
you can do binding in code.
Binding myBinding = new Binding("MyView");
myBinding.Source = this;//the instance with the MyView property
mydatagridctrl.SetBinding(ItemsControl.ItemsSourceProperty, myBinding);
Try adding this to the end of your DataSet_Add_Click
method
dg1.Items.Refresh();