rehan88
rehan88

Reputation: 19

Set Focused Row automatically After Delete

I have a dev-express grid view with data in form of rows and columns inside it. I have implementd a delete functionality now i want that if user deletes a row then control should automatically set row previous to it as the focused row and user can delete again without reselecting the row.

How can i set focusedRow Automatically....

Upvotes: 0

Views: 7689

Answers (2)

Malik Hakyemez
Malik Hakyemez

Reputation: 21

This is the previus row;

        private void backgroundWorkerDelete_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        try
        {
            progress1.Visible = false;

            gridView1.GetFocusedDataRow().Delete();

            gridView1.FocusedRowHandle = gridView1.FocusedRowHandle - 1;
        }
        catch (Exception ex)
        {
            logop.DataErors(ex.Message, "backgroundWorkerDelete_RunWorkerCompleted", "object", this.Name);
        }

    }

Regards

Upvotes: 0

Willem
Willem

Reputation: 9496

Call this method after you have deleted a item.

    public void SelectLastVisibleRow()
    {
        if (gridControl.VisibleRowCount > 1)
        {
            gridControl.View.BeginSelection();
            gridControl.View.ClearSelection();
            gridControl.View.SelectRow(gridControl.VisibleRowCount - 1);
            gridControl.View.MoveFocusedRow(gridControl.VisibleRowCount - 1);
            gridControl.View.EndSelection();
        }
    }

Hope this help.

New Version:

gridControl1.View.FocusedRowHandle = gridControl.VisibleRowCount - 1

Getting selected rows:

((TableView)gridControlSearchResults.View).SelectedRows

Upvotes: 2

Related Questions