سؤال

ok so in C# .NET 4.5 and using a DataGrid

I have my datagrid bound to an ADO.Net DataEntity. Now if i highlight an existing row in the Datagrid and hit a button that I have executing the following code: IList rows = DataGrid.SelectedItems; i can step through the code and see the IList get populated with the proper values.

my datagrid is bound in the XAML as ItemsSource="{Binding}" and each column in the datagrid is bound to a column in the entity like such: Binding="{Binding Path=InventoryName, Mode=TwoWay}"

and in the code behind I set it using a LINQ query to the entity framework like this:

var fillList = (from g in MyDataEntities.Table1
            where g.OnLIst == true
            orderby g.InventoryName
            select g);
DataGrid.ItemsSource = fillList.ToList(); 

What I need to do is twofold: on the RowEditEnding event populate the IList with the vales in the row. Once its populated I need to access the individual entries in the IList.

Through testing and stepping through the code, i think my problem is that when I am entering a blank row, it hasn't updated the entity when the RowEditEnding event has fired. I think this because when i step through the code and expand the IList all the values in it are null. Do I have to do something to update the entity before I fill the IList?

Once its filled how can I access the individual values? when i try to populate a variable using a foreach statement, all it shows the value as: Namespace.TableName

هل كانت مفيدة؟

المحلول

Try this one, It may be help to your question.

List<Table1> TestCollection = new List<Table1>();

public void BindData()
{
     TestCollection = MyDataEntities.Table1.Where(x=>x.OnLIst == true).ToList();
     DataGrid.ItemsSource = TestCollection;
}

then you can access your data each one by one selecting on the Datagrid.

private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
     Table1 NewTable = TestCollection[DataGrid.SelectedIndex];
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top