We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Deleting rows

Thread ID:

Created:

Updated:

Platform:

Replies:

61485 May 26,2007 07:17 AM Jun 4,2007 04:26 PM Windows Forms 3
loading
Tags: GridControl
Alex
Asked On May 26, 2007 07:17 AM

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

Jeba S [Syncfusion]
Replied On May 28, 2007 02:58 AM

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.

Mady
Replied On June 4, 2007 11:36 AM



>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

haneefm [Syncfusion]
Replied On June 4, 2007 04:26 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;