Deleting rows

Hi!

In my test app I'm learning Your DataBoundGrid. So.

I have DataBoundGrid. It's DataSource - BindingSource by microsoft, in which DataSource is simple DataTable. When I'm selecting group of rows (by clicking on their row headers) and then clicking Del-key - they will disappear. So, if they will be removed from DBG's DataSource (from DataTable)?
And second. When I do these operations and then fills DataTable again (just make Refresh), sometimes (very often) in my DBG there is only 2-3 records, so I need to restart my app to see my changes, I've done before.
Here is some code:

//-How DBG is refreshing:
private void BindGrid()
{
m_Data.Fill();

// I need to do this, cuz when I launch my app, fills my DataTable with data, and then try to change headers text - exception occures - columns count in DBG==0 :( gridDataBoundGrid1.GridBoundColumns.Clear();

foreach (DataColumn dc in m_Data.MainTable.Columns)
{
Syncfusion.Windows.Forms.Grid.GridBoundColumn gbc = new Syncfusion.Windows.Forms.Grid.GridBoundColumn();
gbc.HeaderText = dc.Caption;
gbc.MappingName = dc.ColumnName;
gridDataBoundGrid1.GridBoundColumns.Add(gbc);
}

this.gridDataBoundGrid1.Binder.InitializeColumns();
this.gridDataBoundGrid1.Refresh();
}

// How rows are deleting
private void DeleteRow()
{
// ID is current selected PriKey for DataTable
if (ID != 0)
{
m_Data.DeleteMainRecord(Convert.ToInt64(ID));
}

m_Data.MainTable.Rows[bindingSourceMain.Position].Delete();
m_Data.MainTable.AcceptChanges();
}

private void gridDataBoundGrid1_RowsDeleted(object sender, Syncfusion.Windows.Forms.Grid.GridRowRangeEventArgs e)
{
m_bMultipleDeletion = true;

try
{
for (int i = e.From; i <= e.To; ++i)
{
bindingSourceMain.Position = e.From - 1;
DeleteRow();
}
}
catch (Exception ex)
{
Common.Logging.Log(ex);
}

m_bMultipleDeletion = false;
}

Is there any ideas how to do this (delete selected rows and refresh DBG) more simple?

Regards,
Alex

3 Replies

JS Jeba S Syncfusion Team May 28, 2007 06:58 AM UTC

Hi Alex,

Thank you for your code snippets.

I have DataBoundGrid. It's DataSource - BindingSource by microsoft, in which DataSource is simple DataTable. When I'm selecting group of rows (by clicking on their row headers) and then clicking Del-key - they will disappear. So, if they will be removed from DBG's DataSource (from DataTable)?

Answer:
~~~~~~
By default, GridDataBoundGrid will remove records from the DataTable, when Del key is pressed.

And second. When I do these operations and then fills DataTable again (just make Refresh), sometimes (very often) in my DBG there is only 2-3 records, so I need to restart my app to see my changes, I've done before.

Answer:
~~~~~~
Please try to reset the grid first and assign the datasource and see if that avoids the problem.

this.gridDataBoundGrid1.DataSource = null;
this.categoriesTableAdapter.Fill(this.northwindDataSet.Categories);
this.gridDataBoundGrid1.DataSource = this.bindingSource1;
this.gridDataBoundGrid1.DataMember = "Categories";


You can use the Binder.RemoverRecords method to delete rows.

DataTable table = (DataTable) gridDataBoundGrid1.DataSource;
int curRowIndex = gridDataBoundGrid1.CurrentCell.RowIndex;
if (gridDataBoundGrid1.Model.RowCount > 1 && curRowIndex > 0&& gridDataBoundGrid1.Model.RowCount > curRowIndex )
{
int recNumber = this.gridDataBoundGrid1.Binder.RowIndexToPositioncurRowIndex);
this.gridDataBoundGrid1.Binder.RemoveRecords(recNumber, recNumber);
}
else
{
Console.WriteLine("No More rows / CurCell is not set");
}
}


Kindly let us know if you need any further assistance.

Best Regards,
Jeba.


MA Mady June 4, 2007 03:36 PM UTC



>Hi Alex,

Thank you for your code snippets.

I have DataBoundGrid. It's DataSource - BindingSource by microsoft, in which DataSource is simple DataTable. When I'm selecting group of rows (by clicking on their row headers) and then clicking Del-key - they will disappear. So, if they will be removed from DBG's DataSource (from DataTable)?

Answer:
~~~~~~
By default, GridDataBoundGrid will remove records from the DataTable, when Del key is pressed.

And second. When I do these operations and then fills DataTable again (just make Refresh), sometimes (very often) in my DBG there is only 2-3 records, so I need to restart my app to see my changes, I've done before.

Answer:
~~~~~~
Please try to reset the grid first and assign the datasource and see if that avoids the problem.

this.gridDataBoundGrid1.DataSource = null;
this.categoriesTableAdapter.Fill(this.northwindDataSet.Categories);
this.gridDataBoundGrid1.DataSource = this.bindingSource1;
this.gridDataBoundGrid1.DataMember = "Categories";


You can use the Binder.RemoverRecords method to delete rows.

DataTable table = (DataTable) gridDataBoundGrid1.DataSource;
int curRowIndex = gridDataBoundGrid1.CurrentCell.RowIndex;
if (gridDataBoundGrid1.Model.RowCount > 1 && curRowIndex > 0&& gridDataBoundGrid1.Model.RowCount > curRowIndex )
{
int recNumber = this.gridDataBoundGrid1.Binder.RowIndexToPositioncurRowIndex);
this.gridDataBoundGrid1.Binder.RemoveRecords(recNumber, recNumber);
}
else
{
Console.WriteLine("No More rows / CurCell is not set");
}
}


Kindly let us know if you need any further assistance.

Best Regards,
Jeba.

hi there..

i am using c#.net 2003 where i could not find DataGrid.Binder and DataGrid.Model classes..can u plz help me what is the problem should i add any classes in header or any other solution..i would appreciate if u can write me code for Editing and Modifying a record in DataGrid also?

thanking you

mady


HA haneefm Syncfusion Team June 4, 2007 08:26 PM UTC

Hi Mady,

Please follow to the below forum thread for more details.
http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=61884

Best regards,
Haneef

Loader.
Up arrow icon