This is a migrated thread and some comments may be shown as answers.

Implenting Blank new row issue on Filter/Sort

4 Answers 160 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jessica
Top achievements
Rank 1
Jessica asked on 28 Feb 2012, 09:24 PM
I am implementing my own blank row to display at the end of the grid where users will be allowed to enter new data.

I do this by adding an empty row to the end of my ItemsSource

The issue is on Filtering and Sorting the empty row is included in the action. I tried removing the row and then re-adding it  on the Filtering/Filtered and Sorting/Sorted events but on re-add the item is added to the sorted position not the end of the grid. Any help?

For reference this is how I set my DataContext for the Grid.
public DataTable CurrentDataTable
       {
           get { return dataGridView.ItemsSource != null ? ((BindingSource) dataGridView.ItemsSource).DataSource as DataTable : null; }
           set
           {
               CurrentSelectedTableName = value.TableName;
 
               //BindingSource to sync DataTable and DataGridView
               var bSource = new BindingSource {DataSource = value};
 
               //set the DataGridView DataSource
               dataGridView.DataContext = bSource;
           }
       }



Add and Unload Empty Row
public void LoadExtraRow()
 {
      var itemSourceDataTable = CurrentDataTable;
      if (itemSourceDataTable == null)
           return;
      var newRow = itemSourceDataTable.NewRow();
      newRow.RowError = "NEW_ROW";
      itemSourceDataTable.Rows.Add(newRow);
      dataGridView.Rebind();
 }
  
public void UnloadExtraRow()
{
      var itemSourceDataTable = CurrentDataTable;
      if (itemSourceDataTable == null)
           return;
      if (itemSourceDataTable.Rows.Count > 0)
      {
          var emptyRowToRemove = itemSourceDataTable.Rows[itemSourceDataTable.Rows.Count - 1];
          if (emptyRowToRemove.RowError == "NEW_ROW")
          {
               itemSourceDataTable.Rows.Remove(emptyRowToRemove);
          }
       }
   }





4 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 02 Mar 2012, 12:33 PM
Hi Jessica,

Unfortunately, the only solution that we could think of is to save the sort and filter descriptors on the adding of the new item, and restore them on the completion of the add. Please look at the attached sample to see what I mean, and if you have any questions, please don't hesitate to ask!

Hope this helps! 

Regards,
Nik
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jessica
Top achievements
Rank 1
answered on 05 Mar 2012, 03:40 PM
I don't think this does what I need. Maybe I wasn't too clear...

I want the empty row that I am adding to the grid to always be displayed at the end of the grid.
- if the grid is sorted I want the empty row to always remain at the bottom
- if the grid is filtered I want the empty row to always be included in the filtered results and displayed at the bottom of the grid.

0
Vlad
Telerik team
answered on 05 Mar 2012, 03:41 PM
Hello,

We are sorry for this misscommunication.  I'm afraid that this is not support in RadGridView. 

Greetings,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
David
Top achievements
Rank 1
answered on 15 Nov 2012, 05:36 AM
Is Telerik planning to support this feature? This feature is very useful.
Tags
GridView
Asked by
Jessica
Top achievements
Rank 1
Answers by
Nick
Telerik team
Jessica
Top achievements
Rank 1
Vlad
Telerik team
David
Top achievements
Rank 1
Share this question
or