This is a migrated thread and some comments may be shown as answers.

Databinding to BindingList

1 Answer 229 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Abhilash
Top achievements
Rank 1
Abhilash asked on 11 Oct 2010, 09:31 AM
Hi,

I have a query on the DataBinding of DataGridView to BindingList object.

I have a Class called Customer having a structure decribed as Below.

 

public class Customer

 

{

 

public int CutomerType { get; set; }

 

 

public string CustomerName { get; set; }

 

}

 


public
class LookupData

 

{

 

public int Key

 

{

 

get;

 

 

set;

 

}

 

public string Value

 

{

 

get;

 

 

set;

 

}

 

public override string ToString()

 

{

 

return this.Value;

 

}

}

I have created a BindingList<Customer> and binded with the DataGrid. The Grid has 2 columns

1) GridViewComboBoxColumn - with Data source as List of Lookup data and the FieldName as CustomerType
2) GridViewTextBoxColumn - for CustomerName

Everything works fine , I am able to Add, Update and Delete entries.

But my problem is When I add a new row the , the new customer object is added to the BindingList only after I come out of the Grid row.
 
I want to add a new Customer Item to my BindingList when the user adds a new row and selects a CustomerType.

Note : I checked with Normal Winform Grid and It adds an entry if I select Customer Type alone.

Can you please let me know if there is any option available for this..

Thanks
Abhilash

1 Answer, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 11 Oct 2010, 10:05 AM
Hello Abhilash,

This is the normal behavior for the RadGridView, and this happens because of cell / row validation.
For the order of the validation events, please see this article.

If you want to force an insert you can call radGridView1.EndEdit() or inside the CellEndEdit event you can check for a specific column and force an update of the DataSource like this:
void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    var editManager = sender as GridViewEditManager;
    if (e.Column.Name == "Name")
    {
        //radGridView1.EndEdit();
           //or
        editManager.EndEdit();
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Tags
GridView
Asked by
Abhilash
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or