PC Review


Reply
Thread Tools Rate Thread

How do i best search a DataTable if some rows has been deleted.

 
 
Tony Johansson
Guest
Posts: n/a
 
      10th May 2009
Hello!

I have a DataGridView that is connected to a DataTable like this.
DataTable _dataTable = new DataTable();
BindingSource _bindingSource = new BindingSource();

_bindingSource.DataSource = _dataTable;
dgvStock.DataSource = _bindingSource;

When I want to delete a row from the DataGridView I select the row and press
the delete button.
I have the event handler below
Private void btnDelete_Click(object sender, EventArgs e)
{
_dataTable.DefaultView.Delete(dgvStock.CurrentCell.RowIndex);
}

This work good.

I have also a text field in my form which is named txtProdNr where a can
input a productnumber to search for in the DataGridView.
This work good unless I haven't remove any row from the DataGridView.
Here is the event handler for my search button.
private void BtnSearch_Click(object sender, EventArgs e)
{
for (int i = 0; i < _dataTable.Rows.Count; i++)
{
if ((txtProdNr.Text.ToUpper() ==
_dataTable.Rows[i]["ProdNr"].ToString()))
dgvStock.Rows[i].Selected = true;
}
}

I would like to rewrite this event handler for the search button so it works
every time.
So I should only be able to find those productnumber that is visible(not
deleted) in the DataGridView.

Can anybody tell me how this should be written.

//Tony


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i best search a DataTable if some rows has been deleted. Tony Johansson Microsoft C# .NET 10 11th May 2009 02:58 AM
Working with DataTable Deleted Rows =?Utf-8?B?cmFuZHkxMjAw?= Microsoft C# .NET 4 27th Jul 2007 03:00 PM
Get deleted rows from a datatable Andrea Caldarone Microsoft ADO .NET 2 24th Jan 2007 01:57 PM
DataTable, SqlDataAdaptor and updating deleted rows (v1.1) Chris Chilvers Microsoft ADO .NET 0 29th Apr 2006 07:25 AM
DataTable view without deleted rows =?Utf-8?B?U3RldmUgTm9ybWFu?= Microsoft ADO .NET 1 2nd Feb 2005 04:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:09 AM.