• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4224
  • Last Modified:

Remove a row from C# datagrid

Hi all, coding c# in vs.net 2003.

I have the return dataset of a stored procedure bound to a datagrid with one of the fields being status.  The displayed records are filtered using a combo box so that all the records of one status are displayed.  The user has the ability to change the status of a single record and I'm wondering how I can update the datagrid to reflect this change.  Is there a clean way of removing a single record?

For example, if the filter is set to "Good" status then all records displayed have a status of "Good".  If the user changed the status of a record to "Bad" I'd like to remove that record since it no longer matches the filter.  I know that I could just call my stored procedure again and rebind the datagrid but I don't want my grid to be refreshed.  Let's say the user has scrolled down three pages and changes the status of a record, a refresh would repopulate and lose their selection/sorting.
0
alexatsearidge
Asked:
alexatsearidge
1 Solution
 
sabeeshCommented:
You have to reload the grid
0
 
alexatsearidgeAuthor Commented:
My client is particular about this.  He doesn't want the grid to be refreshing and jumping all over.  Is there a seamless way to rebind and minimalize load times
0
 
riyazthadCommented:
Better to use DataView as data source for grid. And filter as per user selected by using Filter method of dataview. You can also delete a row by using dataGridView1.Rows.RemoveAt(1);.

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Gautham JanardhanCommented:
or @ first u could load all the data from the back end
and each time a filter is applied instead of fetching from the back end  set the
DataTable.DefaultView.RowFilter.
but this is advisable only when the total number of records is comparitively low
else the loaading the first time would take a long time
0
 
anyoneisCommented:
This should work just fine:

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
                  string status = comboBox1.SelectedItem.ToString();
                  dataSet1.Tables[0].DefaultView.RowFilter = string.Format("Status = '{0}'", status);
                  dataGrid1.Refresh();
            }
0
 
anyoneisCommented:
The only other code of note is:

     dataGrid1.DataSource = dataSet1.Tables[0];

When you bind to a table, you are really binding to a view - specifically the default view for the table. This default view has a RowFilter which you can set dynamically. The DataGrid, responds to any changes in the datasource, including those induced by changing data in a row (so that the filter excludes them) and by changes in the filter.

David
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now