开发者

WPF DataGrid Full Row Editing

I have a WPF datagrid which works for what I want, but there are two cells in each row which can be edited. Is it possible to place both of these rows into edit mode when the row is edited, then fire the update when the row edit ends/the row loses focus? Currently, after each cell is edit, RowEditEnding fires and the user must wait for the UI to redraw after the commit. The code I'm using is:

 private bool isManualEditCommit;
 private void dg_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if(e.EditAction!= DataGridEditAction.Commit)
                return;
            var newProd = dgLists.SelectedItem as IProduct;
            if(newProd==null)
                return;
                    worker = new BackgroundWorker();
                    worker.DoWork += (s, dwe) =>
                    {
            ... commit update
                    };
                    worker.RunWorkerCompleted += (s, rwe) =>
                    {
                        ... refresh grid
                    };
                    worker.RunWorkerAsync();
        }
    /// <summary>
    /// Commits edits when a cell edit ends.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Windows.Controls.DataGridCellEditEndingEventArgs"/> instance containing the event data.</param>
    private void dg_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) {
        if (e.EditAction == DataGridEditAction.Commit)
        {
            if (!isManualEditCommit)
            {
                isManualEditCommit = true;
                DataGrid grid = (DataGrid) sender;
                grid.CommitEdit(DataGridEditin开发者_如何学GogUnit.Row, true);
                isManualEditCommit = false;
            }
        }


I quit using DataGrid for editing. I use the ListView then provide then provide a GridView as the ListView.View. Inside the GridView you can create GridViewColumns with CellTemplates. The last column of each GridView row is a button to delete that row. Instead of supporting a browse and edit mode, I just support an edit mode. The application moves more fluidly and I don't have any of the headaches that comes along with working with the DataGrid.


Full row editing is the default functionality. The only reason the update is firing per cell edit is that you have implemented the dg_cellEditEnding method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜