Solved

WPF DataGrid Display Errors

Posted on 2013-01-29
13
1,592 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
  • 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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now