Why is the desired data not displayed after changing the value in the row of a column in the datagrid in WPF?

Mojtaba_Hakim 281 Reputation points
2022-09-19T20:11:19.427+00:00

Why is the desired data not displayed after changing the value in the row of a column in the datagrid in WPF?

I have a DataGrid in the C# WPF project and DataGrid's Itemsource fill from the code behind I set a default value for one of my columns but it does not display it until I double click on the column!

also in CellEndEdit I test to change the value of the next column, but it dint show it in real time until I double click it (Click to Edit it)

What have I tried after changing data :

DGR_SUB_INVOLST.Items.Refresh();  
  
DGR_SUB_INVOLST.BeginEdit();  
  
DGR_SUB_INVOLST.CommitEdit();  
  
DGR_SUB_INVOLST.InvalidateVisual();  
  
DGR_SUB_INVOLST.UpdateLayout();  

non of them work! please guide me

full info : why-is-the-desired-data-not-displayed-after-changing-the-value-in-the-row-of-a-c

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,681 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,307 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
767 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rajanikant Hawaldar 86 Reputation points
    2022-10-17T07:15:56.01+00:00

    modify the Cell as below:

    Getting Column and Row Index:

    private void DGR_SUB_INVOLST_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)  
    {  
            if (DGR_SUB_INVOLST != null)  
            {  
                if (DGR_SUB_INVOLST.Items.Count > 0)  
                {  
                    OldRowitem = (INVOMonitor)DGR_SUB_INVOLST.CurrentItem;  
                    DataGridColumn col1 = e.Column;  
                    DataGridRow row1 = e.Row;  
                    OldRowindex = ((DataGrid)sender).ItemContainerGenerator.IndexFromContainer(row1);  
                    OldColumnindex = col1.DisplayIndex;  
                }  
            }  
    }  
    

    A method to get Cell:

    private DataGridCell GetCellVal(string NAME_SUTUN,int ROWINEX)  
    {  
            var TheCol = DGR_SUB_INVOLST.Columns.FirstOrDefault(c => c.SortMemberPath == NAME_SUTUN).DisplayIndex;  
            var DGCInf = new DataGridCellInfo(DGR_SUB_INVOLST.Items[ROWINEX], DGR_SUB_INVOLST.Columns[TheCol]);  
            var TheDGCell = PublicVRB.GetDataGridCell(DGCInf);  
            return TheDGCell;  
    }  
    

    use like:

    private void DGR_SUB_INVOLST_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)  
    {  
        if (DGR_SUB_INVOLST != null)  
        {  
            if (DGR_SUB_INVOLST.Items.Count > 0)  
            {  
                   (e.Row.Item as INVOMonitor).CODE  = SomeValue;  
         ((TextBlock)GetCellConfig("Binding_Name", row_index).Content).Text = (e.Row.Item as INVOMonitor).CODE.ToString();  
            }  
        }  
    }  
    
    0 comments No comments