Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a set of items, let's say Person:

C#
public class Person : INotifyPropertyChanged, INotifyDataErrorInfo
{
  // INotifyPropertyChanged and INotifyDataErrorInfo code goes here

  private string name;

  public string Name
  {   
      get { return name; }
      set 
       {
          name = value;
          RaisePropertyChanged("Name");
          Validate("Name");
       }
  }


  private int age;

  public int Age
  {   
      get { return age; }
      set 
       {
          age= value;
          RaisePropertyChanged("Age");
          Validate("Age");
       }
  }
}

//Validation code


I managed to get the validation working, however I don't know how to display the item's Error when user inputs figure 18 and below as the tooltip because the tooltip shows the viewmodel's errors instead. How can I get the datagridcell tooltip to instead show error of the Person object instead?

Here's the Datagrid code:

XML
<DataGrid ItemsSource="{Binding PersonsList, Mode=TwoWay, UpdateSourceProperty=PropertyChanged}", AutoGenerateColumns="False">
    <DataGridTextColumn Header="Name" Text="{Binding Name, Mode=TwoWay, UpdateSourceProperty=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
    <DataGridTextColumn Header="Age" Text="{Binding Age, Mode=TwoWay, UpdateSourceProperty=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
</Datagrid>


What I have tried:

I Have no idea what to do here
Posted
Comments
[no name] 29-Jan-21 10:09am    
Life would be simpler if you used a form for the CRUD portion.

Also, if you use nameof() instead of hard-coding your property names, you have the benefit of compiler checking and you're also able to list references for that property.
Lyandor 29-Jan-21 20:45pm    
Hi, I've never seen binding with nameof before, is the syntax Text="{Binding NameOf(Name).....}"?

I'm not familiar with using forms, are you refering to using Winforms UserControls in the WPF application?
[no name] 29-Jan-21 22:21pm    
Not in the XAML; in the C# code: e.g. Validate( nameof(Name) ) instead of ... "Name" ...

A "form" (lower case) is an WPF Window, User Control, or Windows Form, that is used to operate on a "single record" versus wrestling with a multi-record data grid for CRUD operations.

https://www.c-sharpcorner.com/UploadFile/1e050f/insert-update-and-delete-record-in-datagridview-C-Sharp/

Lyandor 29-Jan-21 23:04pm    
Ahh yes, very true. However, in users' POV, using forms for DataGrid manipulation is slow. I am required to make every step in the application as simple and straightforward as possible due to low quality manpower here. As such, I will need to rely on direct editing in DataGrid many times in the application.
[no name] 30-Jan-21 6:45am    
That's a pretty narrow view. My "forms" also page forward, backwards, first record, last record, copy last record, etc. (keyboard short-cuts)

And what happens when the number of "fields" (i.e. "columns") exceeds the width of the screen? Scrolling sideways while editing?

As I said, a pretty narrow view.

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