Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
380
How to set default value of cell when adding a new record
posted

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

 

Parents
No Data
Reply
  • 69686
    posted

     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?

Children