Solved

WPF DataGrid Display Errors

Posted on 2013-01-29
13
1,684 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
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 

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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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