Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WPF DataGrid Display Errors

Posted on 2013-01-29
13
Medium Priority
?
1,753 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 1500 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

885 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