Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:50:01+00:00 2026-05-15T14:50:01+00:00

I have the following validation method in my viewmodel (example is showing only one

  • 0

I have the following validation method in my viewmodel (example is showing only one column, “ItemNumber”):

public bool IsValid
{
  get
  {
    foreach (string property in ValidatedProperties)
      if (GetValidationError(property) != null)
        return false;

    return true;
  }
}

static readonly string[] ValidatedProperties = 
{ 
  "ItemNumber"
};

string GetValidationError(string propertyName)
{
  if (Array.IndexOf(ValidatedProperties, propertyName) < 0)
    return null;

  string error = null;

  switch (propertyName)
  {
    case "ItemNumber":
      error = this.ValidateItemNumber();
      break;
    default:
      Debug.Fail("Unexpected property being validated on ProjectExpense: " + propertyName);
      break;
  }
  // set the status message on the UI to the generated error
  if (error != null)
  {
    ErrorMessage = error;
  }

  return error;
}

// string method
static bool IsStringMissing(string value)
{
  return String.IsNullOrEmpty(value) || value.Trim() == String.Empty;
}

string ValidateItemNumber()
{
  if (SelectedProjectExpenseItem != null)
  {
    if (IsStringMissing(SelectedProjectExpenseItem.ItemNumber))
    {
      return "Item number is required";
    }
    if (SelectedProjectExpenseItem.ItemNumber.Length > 50)
    {
      return "Item number exceeds 50 characters";
    }
  }
  return null;
}

#endregion


#region IDataErrorInfo Members

string IDataErrorInfo.Error { get { return null; } }

string IDataErrorInfo.this[string propertyName]
{
  get { return this.GetValidationError(propertyName); }
}

The validation fires, but I don’t know how to communicate it to my datagrid. I am using a separate Dto (hence SelectedProjectExpenseItem.ItemNumber above, SelectedProjectExpenseItem is my Dto) instead of having the properties directly in my viewmodel. Here is my datagrid:

  <DataGrid ItemsSource="{Binding Path=ListOfProjectExpenseItems}" AutoGenerateColumns="False" 
      Name="dgProjectExpenseItems" SelectionMode="Single" SelectionUnit="FullRow" CanUserResizeColumns="True" 
      SelectedItem="{Binding Path=SelectedProjectExpenseItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" GridLinesVisibility="Horizontal" CanUserDeleteRows="True" CanUserAddRows="True">
    <DataGrid.Columns>
      <DataGridTextColumn Header="ID" Width="SizeToCells" MinWidth="50" Binding="{Binding RowID}" />
      <DataGridTextColumn Header="Project Expense ID" Width="SizeToCells" Visibility="Hidden" MinWidth="0" Binding="{Binding ProjectExpenseID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
      <DataGridTextColumn Header="Item Number" Width="SizeToCells" MinWidth="140" Binding="{Binding ItemNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
      <DataGridTextColumn Header="Item Description" Width="SizeToCells" MinWidth="250" Binding="{Binding ItemDescription, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
      <DataGridTextColumn Header="Unit Price" Width="SizeToCells" MinWidth="90" Binding="{Binding ItemUnitPrice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
      <DataGridTextColumn Header="Qty" Width="SizeToCells" MinWidth="65" Binding="{Binding ItemQty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
      <DataGridTextColumn Header="Supplier Name" Width="SizeToCells" MinWidth="200" Binding="{Binding SupplierName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
    </DataGrid.Columns>
  </DataGrid>

I would like to use a style, say with a red border and tooltip stating the error, to signify a problem with the row or cell. Every example I found using styles, however, has the properties directly in the viewmodel, and I cannot figure out how to port it over to my Dto.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:50:01+00:00Added an answer on May 15, 2026 at 2:50 pm

    The problems had to do with using Dto’s in my implementation, or at least the lack of implementing IDataErrorInfo in them. I decided to dump them and go with straight business objects that implement IDataErroInfo and wa-la, everything works beautifully now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>
I have a custom validation method that ensures an alarm can only be set
In Spring MVC I have the following controller: @RequestMapping(value=adminUsers, method = RequestMethod.POST) public ModelAndView
I have the following validation rule on one of the models, validates :reciept_num, :presence
i have following method of Jquery Validation: jQuery.validator.addMethod(alpha, function(value, element) { return this.optional(element) ||
I have the following validation summary control in the markup: <asp:ValidationSummary ID=vsValErrs CssClass=errors HeaderText=<div><%#
I have the following validation in a model: validates_length_of :description, :minimum => 2, :on
I have the following script validation.php <?php if(!isset($_SESSION['userId'])){ session_destroy(); header('Location: home.php'); exit; } ?>
I have the following code validation php script: if(empty($_POST['captcha_code'])) { $error = 1; $code[3]
I have been following the validation for Entry boxes from here . The code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.