We bind BindingList<T> to XamDataGrid.DataSourceProperty, and add a new event to
BindingList’s AddingNew like following:
BindingListData.AddingNew += new AddingNewEventHandler(OnAddingNew);
The OnAddingNew function, we create T (the row data) and set e.NewObject = newly created T like following:
void OnAddingNew(object sender, System.ComponentModel.AddingNewEventArgs e)
{
Create T;
e.NewObject = newly created T;
}
when user enters a character in any cell on the top row OnAddingNew () is called. The created row is already added to the binding list.
Our question is we have already set the default value of cell in the T’s constructor, why the cell of new row is still blank? We have set two way binding for the field, but the new record on the top seems like one way binding,.
Anyone give some idea about how to solve this problem
Hello Sagar,
As John suggested you should add an empty constructor. No matter your entity is auto generated, you can still edit the .cs file in order to add the constructor.
Hey John,
How can i achieve this functionality, to set pre defined values to a grid when i am populating the data from entityframework?
My grid has a DataBinding to an Entity(ABC) and i the autogenerated code or the entity file ABC.cs is a partial class and doesnt have a constructor. How can you tell me how can i set the predefined values while adding a new row?
Thanking you in advance.
Regards,
Sagar
Hello,
I have reproduced this scenario. For my class <T> I used both constructor with and without parameters. The Default constructor I set the Default values of the new objects. When I add new row, the default values for the cells appear but only when one of the cells enters EditMode and something is typed in (for example text or number). I did not use any additional settings like bindings or handling events. This is the correct behavior of the XamDataGrid. Here is a screenshot of what I have created and the code of my class.
public class Cars { public string Color { get; set; } public string Model { get; set; } public bool IsCool { get; set; } public Cars(string model, string color, bool iscool) { Model = model; Color = color; IsCool = iscool; } public Cars() { Model = "New Model"; Color = "New Color"; IsCool = false; } }
Am I missing something?