Re: Datagridview.datasource triggers RowsAdded event twice
- From: "Patrik" <Hedge@xxxxxxxxxxxxxxxx>
- Date: Tue, 20 Feb 2007 15:33:40 +0100
The dataTable is populated as start of the program using a xml-file and
MSDataSetGenerator. Later when entering a specific view I will bind a
datagridview to that table. Why I need to use the RowsAdded event is that I
need to populate a combox column that will have items that are unique for
ech cell in that column.
So as I understand it the Bindingsource will react when I populate the
dataTable which happens at start of the program. Later when entering a
specific view I bind these values to a gridView and react to the RowsAdded
to be able to populate the combobox for each row. So the data i get from the
dataTable shall be the SelectedItem for the combobox.
/Patrik
"ClayB" <clayb@xxxxxxxxxxxxxx> wrote in message
news:1171975410.342184.154860@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You could wrap your DataTable in a BindingSource object and then
listen to the BindingSource.ListChanged event (or the AddingNew event)
for ListChangedType.ItemAdded to catch (only once) the adding of new
rows to the DataTable. (Or, you could access the CurrecnyManager.List
for this bindingcontext and listen to its ListChanged event, but this
you could not do from the designer).
Here is the code changes in you sample to show this (I think you can
also do it from the designer as well.)
private BindingSource src;
...//in Form_Load
dataGridView1.DataSource = this.src;
...//in FillDataSet()
DataTable table = new DataTable("table1");
this.src = new BindingSource();
src.DataSource = table;
src.ListChanged += new
ListChangedEventHandler(src_ListChanged);
void src_ListChanged(object sender, ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded)
{
Console.WriteLine(string.Format("added {0}", e.NewIndex));
}
}
===================
Clay Burch
Syncfusion, Inc.
.
- Follow-Ups:
- Re: Datagridview.datasource triggers RowsAdded event twice
- From: "Jeffrey Tan[MSFT]"
- Re: Datagridview.datasource triggers RowsAdded event twice
- References:
- Datagridview.datasource triggers RowsAdded event twice
- From: Patrik
- Re: Datagridview.datasource triggers RowsAdded event twice
- From: ClayB
- Re: Datagridview.datasource triggers RowsAdded event twice
- From: Patrik
- Re: Datagridview.datasource triggers RowsAdded event twice
- From: "Jeffrey Tan[MSFT]"
- Re: Datagridview.datasource triggers RowsAdded event twice
- From: Patrik
- Re: Datagridview.datasource triggers RowsAdded event twice
- From: "Jeffrey Tan[MSFT]"
- Re: Datagridview.datasource triggers RowsAdded event twice
- From: ClayB
- Datagridview.datasource triggers RowsAdded event twice
- Prev by Date: Re: Urgent: Controls disapearing from Design Surface...
- Next by Date: DatagridView Validation assistance needed
- Previous by thread: Re: Datagridview.datasource triggers RowsAdded event twice
- Next by thread: Re: Datagridview.datasource triggers RowsAdded event twice
- Index(es):
Relevant Pages
|