Solved

WPF DataGrid Display Errors

Posted on 2013-01-29
13
1,654 Views
Last Modified: 2013-02-12
My WPF DatagRid displays a red exclamation mark when I change data on a row or add a new row.

It is interesting that on a new row the exclamation mark remains whereas on an edited row it disappears after a few seconds after moving to a different row.

How can i see what the errors are?
0
Comment
Question by:Adapt2NL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 38833579
You can get the DataGrid errors from the row, as described in this article:

WPF DataGrid Practical Examples
http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples

<Style x:Key="RowStyle" TargetType="{x:Type dg:DataGridRow}">
    <Setter Property="ValidationErrorTemplate">
        <Setter.Value>
            <ControlTemplate>
                <Grid>
                    <Ellipse Width="12" Height="12"
                        Fill="Red" Stroke="Black"
                        StrokeThickness="0.5"/>
                    <TextBlock FontWeight="Bold" Padding="4,0,0,0"
                        Margin="0" VerticalAlignment="Top" Foreground="White" Text="!"
                        ToolTip="{Binding RelativeSource={RelativeSource
                                 FindAncestor, AncestorType={x:Type dg:DataGridRow}},
                                 Path=(Validation.Errors)[0].ErrorContent}"
/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
0
 

Author Comment

by:Adapt2NL
ID: 38834898
I have added that XAML. I am assuming then if put my mouse over the exclamation mark, I would see a tool-tip. but I don't! Am I missing something?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38834964
Can you show me your XAML please?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Adapt2NL
ID: 38834966
Here is the DatGrid
                        <DataGrid x:Name="inventoryDataGrid" EnableRowVirtualization="True"
                                  ItemsSource="{Binding Source={StaticResource InventoryVS},  diag:PresentationTraceSources.TraceLevel = High}" RowDetailsVisibilityMode="VisibleWhenSelected"
                                  Grid.RowSpan="1"
                                                                  Margin="6" AlternatingRowBackground="AliceBlue" AutoGenerateColumns="False"
                                  IsReadOnly="{Binding EnableOpposite}"
                                      ColumnHeaderStyle="{StaticResource HeaderStyle}" HorizontalGridLinesBrush="{Binding BrushForBorder}"
                                  VerticalGridLinesBrush="{Binding BrushForBorder}"
                                  >
                            <DataGrid.Columns>

                                <DataGridComboBoxColumn Header="Product"
                                                        ItemsSource="{Binding Source={StaticResource MainScreenObject}, Path=Products}"  
                                                      SelectedValueBinding="{Binding lngProductID}"
                                                       
                                                      DisplayMemberPath="strProductName"
                                                      SelectedValuePath="lngHardwareID"
                                                        >
                                   
                                </DataGridComboBoxColumn>
                                <DataGridTextColumn x:Name="strFluent2TagColumn" Binding="{Binding strFluent2Tag}" Header="Fluent2 Tag" Width="Auto"/>
                                <DataGridTextColumn x:Name="strManSerialNumberColumn" Binding="{Binding strManSerialNumber}" Header="Man Serial Number" Width="Auto"/>
                                <DataGridTextColumn x:Name="strManProductCodeColumn" Binding="{Binding strManProductCode}" Header="Man Product Code" Width="Auto"/>
                                <DataGridTextColumn x:Name="strManActivationKeyColumn" Binding="{Binding strManActivationKey}" Header="Man Activation Key" Width="Auto"/>
                                <DataGridTemplateColumn x:Name="dteInstalledColumn" Header="Installed" Width="Auto">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <DatePicker SelectedDate="{Binding dteInstalled, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridCheckBoxColumn x:Name="chkPreventReqColumn" Binding="{Binding chkPreventReq}" Header="Prevent Req" Width="Auto"/>
                                <DataGridTemplateColumn x:Name="dtePMLastDoneColumn" Header="PM Last Done" Width="Auto">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <DatePicker SelectedDate="{Binding dtePMLastDone, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>

                            </DataGrid.Columns>
                        </DataGrid>
0
 

Author Comment

by:Adapt2NL
ID: 38834969
Bound To

        <CollectionViewSource x:Key="CustomerVS" Source="{Binding Customer.CustomerDT, Source={StaticResource MainScreenObject}}"/>
        <CollectionViewSource x:Key="ContactsVS" Source="{Binding FK_Customer_Contact, Source={StaticResource CustomerVS}}"/>
        <CollectionViewSource x:Key="SitesVS" Source="{Binding FK_Customer_Site, Source={StaticResource CustomerVS}}"/>
        <CollectionViewSource x:Key="InventoryVS" Source="{Binding FK_Customer_Inventory, Source={StaticResource CustomerVS}}"/>
0
 

Author Comment

by:Adapt2NL
ID: 38834973
The grid is essentially bound to a DataSet that is poulated via the MainScreen Object
0
 

Author Comment

by:Adapt2NL
ID: 38834975
Please let me know any other information you would like.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38835004
I don't see any ToolTip in the XAML...
0
 

Author Comment

by:Adapt2NL
ID: 38835148
Please excuse my ignorance (I am after all new to WPF) but how would I refer to the style for my tooltip?
Tooltip = ..... what do I write between the quotes?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38836207
OK, now I see how that was implemented.  The example is a Style, that is either an application-level resource (in App.xaml), or window-specific resource (under Window.Resources element).  

The key to the style is TargetType="{x:Type dg:DataGridRow}", which applies this style to the DataGridRow.

This might be a good reference for WPF styles:

A Guided Tour of WPF – Part 5 (Styles)
http://www.codeproject.com/Articles/18388/A-Guided-Tour-of-WPF-Part-5-Styles
0
 

Author Comment

by:Adapt2NL
ID: 38836458
Thank you I will read the article and revert. I am travelling tomorrow and will be away for a week so please excuse me if there is a delay.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 38836489
I should be here whenever you need more advice.
0
 

Author Comment

by:Adapt2NL
ID: 38879343
Thank you for your assistance, I managed by adding the code without using a style. I will read up on styles:)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question