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

Update Dataset with filtered Grid

4 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Guy
Top achievements
Rank 1
Guy asked on 11 Nov 2010, 11:29 AM
Hi,

I'm having a few issues i'm unable to resolve and wondered if someone could give me a quick hand.

I've got a main gridview which shows a list of pre-filtered data for each user after they log in. I used to have controls databound so when a row was selected the details would update and when changes were made using those controls and the save button pressed the dataset would update.

Then someone pointed out that if they grouped some of the data and then changed that same criteria using the controls the bindings would go out of sync and when a further record was selected, the incorrect details would be displayed in the controls. (Basically the agents have a list of customers and a column which shows the next call date. When they group by that to show them the customers they have to call that day, they will then change the next call date and that's when things become out of sync; selecting Customer A doesn't display Customer A in the bound controls).

So I suspected this was because the row index was getting out of sync so I went about rewriting the entire process so that when the row changes it now fills those controls with the currentrow value; this works fine.

My problem is now trying to update the dataset with the changes made to that row. I have used the below code (basic example) but it really doesn't look right and isn't saving the information properly.

private void SaveAccountDetails()
{
    int currentrow = this.radGridView1.Rows.IndexOf(this.radGridView1.CurrentRow);
    mercuryDBDataSet.Main[currentrow].Notes = AccountNotesTextBox.Text;            
    radGridView1.CurrentRow.InvalidateRow();
    MessageBox.Show("Records Updated");
}

I have looked at the value for currentrow and if I try to save the first row in my filtered list it is giving me an index of 0. This is updating the row and the first row in my dataset which isn't what I want.

I found something about GridViewRowInfo on here but not sure if it's the correct way to go and then how to implement it in my code.

I would really appreciate any help!

Regards,

Guy

4 Answers, 1 is accepted

Sort by
0
Guy
Top achievements
Rank 1
answered on 12 Nov 2010, 01:31 PM
Hi,

Just had a thought; it there a way to "refresh" a grouping of filtered list without invoke the fill method?

This would allow me to use my original method which doesn't work as the filtered/grouped selection still displays the entry after the row no longer fits within it.

Regards,

Guy
0
Julian Benkov
Telerik team
answered on 17 Nov 2010, 10:02 AM
Hello Guy,

You can use the GridViewTemplate Refresh method to update the current view, but in your scenario for data update you can use the DataBoundItem property of GridViewRowInfo. This will allow you to achieve the desired functionality without involving the current filtered, grouped or sorted view in your logic:

private void SaveAccountDetails()
{
    DataRowView row = this.radGridView1.CurrentRow.DataBoundItem as DataRowView;
    row["Notes"] = AccountNotesTextBox.Text;           
    radGridView1.CurrentRow.InvalidateRow(); //this update is not needed by default- RadGridView automatically will be updated when data is changed in underline data source
    MessageBox.Show("Records Updated");
}

I hope this helps.

Best wishes,
Julian Benkov
the Telerik team
See What's New in RadControls for WinForms in Q3 2010 on Wednesday, November 17, 11am Eastern Time: Register here>>
0
Guy
Top achievements
Rank 1
answered on 21 Nov 2010, 06:07 PM
Hi Julian,

Sorry for my late reply.

I wondered if you could expand a little on the Refresh method; I have tried both radgrid.refresh() and radgridview.mastertemplate.refresh() and neither seems to refresh the grid.

The entries which the grid is either sorted by or grouped still appear on the list and when a row is selected the bindings dislay a different row details to those of the selected row.

Regards,

Guy
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 22 Nov 2010, 12:36 AM
Hello Guy,

Basically the Refresh() will cause the grid to synchronize with the datasource, and this always happen.

The problem here is in the way you are getting the index of the selected row, because you are grouping / filtering, the index of the row will be the index for that row in that group. If you want to get the real index of the row you should use:
var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentCell.RowInfo);
//or
var rowIndex = radGridView1.MasterView.ViewTemplate.Rows.IndexOf(radGridView1.CurrentRow);

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
Guy
Top achievements
Rank 1
Answers by
Guy
Top achievements
Rank 1
Julian Benkov
Telerik team
Emanuel Varga
Top achievements
Rank 1
Share this question
or