Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a class that has a double variable. I want to enter the number entered in the data grade cells without using data grade events when I enter a number after press enter send value in data grid cell to variable d with a function or method inside the class.

XAML Code:
WPF
<StackPanel>
<DataGrid   Height="120" Name="Grid" Margin="5" />
<Button  Margin="10" Click="ButtonBase_OnClick" >Click</Button>
</StackPanel>


CS code:
C#
namespace WpfApp4
{
    {
        private double d ;
        public   double D
        {
            set
            {
                d = value;
            }
            get
            {
                return d;
            }
        } 

        public override string ToString()
        {
            return D.ToString();
        }
    }

    public partial class MainWindow : Window
    {
        DataTable dt = new DataTable();
        MyClass myClass1=new MyClass();
        MyClass myClass2=new MyClass();
        public MainWindow()
        {
            InitializeComponent();
            dt.Columns.Add(new DataColumn("Double", typeof(MyClass)));
            dt.NewRow();
            dt.Rows.Add(myClass1);
            dt.Rows.Add(myClass2);
            Grid.ItemsSource= dt.DefaultView;
        }
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MessageBox.Show("Value Datatable rows is:" + dt.Rows[i]["Double"]);
            }
            MessageBox.Show("Value D is :" + myClass1.D);        
        }

    }
}


What I have tried:

i can solve it event of datagrid ( cells edit ending) but i want solve it with class and methods
Posted
Updated 6-Nov-20 1:25am
Comments
[no name] 5-Nov-20 19:32pm    
Good luck with your new pattern! Hope it works as well as the old one.
Member 14963069 7-Nov-20 6:19am    
You may give an example. I did not understand anything from your link

1 solution

 
Share this answer
 
Comments
Member 14963069 7-Nov-20 6:22am    
I did not understand anything about mvvm
You may need more guidance
Richard Deeming 9-Nov-20 3:15am    
Then you should start reading. Google will find you plenty of examples and explanations.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900