Change the value in a cell in a datagrid (binding)

Alan392

this is my issue.

When I select a single row and I click on the button, the cell must change value, but it doesn't change anything

enter image description here

This is XAML code.

        <DataGrid 

        ItemsSource="{Binding Dati_Viaggio, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
        SelectedItem="{Binding SelectDati_Viaggio, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

        AutoGenerateColumns="False" HorizontalAlignment="Left" Height="119" Margin="10,10,0,0" VerticalAlignment="Top" Width="497">

        <DataGrid.Columns>
            <DataGridTextColumn x:Name="NumOrd" Binding="{Binding Path=NumOrd, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  Header="NumOrd" Width="150" />
        </DataGrid.Columns>

    </DataGrid>

and this is c# code

Public ObservableCollection<Model_Ricerca_Dati_Viaggio> Dati_Viaggio 
{ get; set; }
private Model_Ricerca_Dati_Viaggio _SelectDati_Viaggio;
public Model_Ricerca_Dati_Viaggio SelectDati_Viaggio {
get { return _SelectDati_Viaggio; }
set {
    _SelectDati_Viaggio = value;
    OnPropertyChanged("SelectDati_Viaggio");}}

private string _NumOrd { get; set; }
public string NumOrd {
get { return _NumOrd; }
set {
    _NumOrd = value;
    OnPropertyChanged("NumOrd");}}

Private void Cmd_TrovaExe()
{
SelectDati_Viaggio.NumOrd = Now.@string;

OnPropertyChanged("NumOrd");
OnPropertyChanged("Dati_Viaggio");
OnPropertyChanged("SelectDati_Viaggio");
}

Why the cell doesn't refres after SelectDati_Viaggio.NumOrd = Now.@string; ?

SamTh3D3v

Your class Model_Ricerca_Dati_Viaggio must as well implements the INotifyChangedinterface in order to the changed to be exposed to the UI :

  public class Model_Ricerca_Dati_Viaggio:INotifyPropertyChanged
{
    private string _numOrd ;
    public string NumOrd  
    {
        get
        {
            return _numOrd;
        }

        set
        {
            if (_numOrd == value)
            {
                return;
            }

            _numOrd = value;
            OnPropertyChanged("NumOrd");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Binding WPF Datagrid cell background colour with trigger

From Dev

WPF Datagrid Get Selected Cell Value

From Dev

How to disable a cell in a DataGrid while binding to an ObservableCollection

From Dev

How to change DataGrid cell background color based on cell value

From Dev

Change null value appearance on DataGrid when binding to DataTable

From Dev

Change binding if value is empty

From Dev

How to set DataGrid cell content depending on binding value?

From Dev

Get Value of a specific cell in DataGrid

From Dev

How to bind value from DataGrid:Cell to DataTrigger

From Dev

Datagrid change a cell value if it's default(dateTime)

From Dev

Change Cell Value if There is Overflow

From Dev

How to change datagrid cell value when user leaves cell

From Dev

WPF DataGrid change Cell background if the cell contains a specific value

From Dev

WPF DataGrid. Change single cell background

From Dev

WPF DataGrid, converting value in cell

From Dev

Datagrid binding to a list based on a value of a property

From Dev

How to set DataGrid cell content depending on binding value?

From Dev

Change DataGrid ItemsSource binding in code-behind

From Dev

WPF DataGrid Cell binding by data from Parent control

From Dev

Cell Style Binding does not Update on Value Change

From Dev

How do I change the value of an individual cell in a WPF datagrid when it is double clicked?

From Dev

Datagrid Combobox Seletected item Value to Textbox binding

From Dev

WPF DataGrid. Change single cell background

From Dev

Cell value change with Month

From Dev

Binding background value in wpf datagrid cell

From Dev

How to change datagrid header to follow other cell value in C# ASP.NET?

From Dev

Change value of cell in Javascript

From Dev

Dev Express DataGrid cell cannot change a value in VB.NET

From Dev

Get selected cell value from DataGrid Cell

Related Related

  1. 1

    Binding WPF Datagrid cell background colour with trigger

  2. 2

    WPF Datagrid Get Selected Cell Value

  3. 3

    How to disable a cell in a DataGrid while binding to an ObservableCollection

  4. 4

    How to change DataGrid cell background color based on cell value

  5. 5

    Change null value appearance on DataGrid when binding to DataTable

  6. 6

    Change binding if value is empty

  7. 7

    How to set DataGrid cell content depending on binding value?

  8. 8

    Get Value of a specific cell in DataGrid

  9. 9

    How to bind value from DataGrid:Cell to DataTrigger

  10. 10

    Datagrid change a cell value if it's default(dateTime)

  11. 11

    Change Cell Value if There is Overflow

  12. 12

    How to change datagrid cell value when user leaves cell

  13. 13

    WPF DataGrid change Cell background if the cell contains a specific value

  14. 14

    WPF DataGrid. Change single cell background

  15. 15

    WPF DataGrid, converting value in cell

  16. 16

    Datagrid binding to a list based on a value of a property

  17. 17

    How to set DataGrid cell content depending on binding value?

  18. 18

    Change DataGrid ItemsSource binding in code-behind

  19. 19

    WPF DataGrid Cell binding by data from Parent control

  20. 20

    Cell Style Binding does not Update on Value Change

  21. 21

    How do I change the value of an individual cell in a WPF datagrid when it is double clicked?

  22. 22

    Datagrid Combobox Seletected item Value to Textbox binding

  23. 23

    WPF DataGrid. Change single cell background

  24. 24

    Cell value change with Month

  25. 25

    Binding background value in wpf datagrid cell

  26. 26

    How to change datagrid header to follow other cell value in C# ASP.NET?

  27. 27

    Change value of cell in Javascript

  28. 28

    Dev Express DataGrid cell cannot change a value in VB.NET

  29. 29

    Get selected cell value from DataGrid Cell

HotTag

Archive