Solved

WPF DataGrid Display Errors

Posted on 2013-01-29
13
1,580 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
Comment Utility
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
Comment Utility
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
Comment Utility
Can you show me your XAML please?
0
 

Author Comment

by:Adapt2NL
Comment Utility
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
Comment Utility
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
Comment Utility
The grid is essentially bound to a DataSet that is poulated via the MainScreen Object
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Expert Comment

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

Author Comment

by:Adapt2NL
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I should be here whenever you need more advice.
0
 

Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

9 Experts available now in Live!

Get 1:1 Help Now