Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:01:12+00:00 2026-05-13T06:01:12+00:00

I have a DataGrid which is bound to a PagedCollectionView and the underlying collection

  • 0

I have a DataGrid which is bound to a PagedCollectionView and the underlying collection may contain no items. When this occurs the DataGrid does not render at all, no column headers or anything, and when the DataGrid is then re-bound to another PagedCollectionView that does contain some items it causes a system error

System.ArgumentException: Value does
not fall within the expected range.
at
MS.Internal.XcpImports.MethodEx(IntPtr
ptr, String name, CValue[] cvData)
at
MS.Internal.XcpImports.MethodEx(DependencyObject
obj, String name) at
MS.Internal.XcpImports.UIElement_UpdateLayout(UIElement
element)…

or

Message: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Collection_InsertValue[T](PresentationFrameworkCollection 1 collection, UInt32 index, CValue value)
at MS.Internal.XcpImports.Collection_InsertDependencyObject[T](PresentationFrameworkCollection 1 collection, UInt32 index, DependencyObject value)
at System.Windows.PresentationFrameworkCollection 1.InsertDependencyObject(Int32 index, DependencyObject value)
at System.Windows.Controls.UIElementCollection.InsertInternal(Int32 index, UIElement value)
at System.Windows.PresentationFrameworkCollection 1.Insert(Int32 index, T value)
at System.Windows.Controls.DataGrid.InsertDisplayedColumnHeader(DataGridColumn dataGridColumn)
at System.Windows.Controls.DataGrid.OnInsertedColumn_PreNotification(DataGridColumn insertedColumn)
at System.Windows.Controls.DataGridColumnCollection.InsertItem(Int32 columnIndex, DataGridColumn dataGridColumn)
at System.Collections.ObjectModel.Collection 1.Insert(Int32 index, T item)
at System.Windows.Controls.DataGridColumnCollection.EnsureRowGrouping(Boolean rowGrouping)
at System.Windows.Controls.DataGrid.EnsureRowGroupSpacerColumn()
at System.Windows.Controls.DataGrid.RefreshRows(Boolean recycleRows, Boolean clearRows)
at System.Windows.Controls.DataGrid.RefreshRowsAndColumns(Boolean clearRows)
at System.Windows.Controls.DataGrid.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

Line: 54
Char: 13
Code: 0

which I assume is caused because the DataGrid is missing a pointer that it should have (but to be honest I really have no idea as I haven’t looked into it).

The system exception is obviously a problem and I’d like it to not happen. But making the UI look nice when there are no items in the collection is a business requirement and I figure that fixing the UI to display something nice when the collection is empty might just give me a work around for the System Exception.

So is it possible to display a message or default row in a Silverlight 3 DataGrid?

I’ve seen Jonathan Shen’s answer but I was wondering if there was an easier/simpler/built in way now days as his answer pre-dates Silverlight 3. I also have an issue with the View having to create, in the example, a Person collection & object. My Views have no knowledge of the ViewModel so to implement Jonathan’s solution I would also have to implement a secondary Person within the View – not the end of the world, but it seems a little hacky.

Does anyone have a better solution for displaying something nice when binding a potentially empty collection to a Silverlight DataGrid?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:01:12+00:00Added an answer on May 13, 2026 at 6:01 am

    I would do this by switching the visibility of the datagrid off and the visibility of say a textblock on. You can do this with binding and a converter:

    Converter:

    public class ObjectToVisibilityConverter : IValueConverter
    {
        public bool Negate { get; set; }
    
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (!Negate)
        {
            return (value == null) ? Visibility.Collapsed : Visibility.Visible;
        }
        else
        {
            return (value == null) ? Visibility.Visible :  Visibility.Collapsed;
        }
    }
    
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    

    }

    XAML:

        <UserControl.Resources>
            <xmlnsref:ObjectToVisibilityConverter x:Key="ObjectToVisibilityConverter" />
            <xmlnsref:ObjectToVisibilityConverter Negate="True" x:Key="ReversedObjectToVisibilityConverter" />
        </UserControl.Resources>
        <StackPanel>
           <data:dataGrid Visibility="{Binding MyDataSetObject, Converter={StaticResource ObjectToVisibilityConverter}}">
           ... />
           <TextBlock Text="No results found."
     Visibility="{Binding MyDataSetObject, Converter={StaticResource ReversedObjectToVisibilityConverter}}"> />
        </StackPanel>
    

    This will hide the grid (and show the textbox) if the MyDataSetObject object is null, and vica-versa if not null (Note the Negate property on the converter that will reverse the visibility)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a silverlight datagrid which is bound to a PagedCollectionView displaying a collection
I have a wpf datagrid which is bound to an observable collection. Currently I
in .net I have created an excel report which takes a datagrid's render output
I have a DataGrid whose ItemsSource is bound to a changing Observable Collection. Inside
I have a DataGrid which is being bound dynamically to a database query. The
Scenario I have a DevExpress DataGrid which is bound to a DataSet in C#.
I have a View that displays a DataGrid which is bound to an ObservableCollection
I have a datagrid and a template column which is bound. I don't understand
I have created a datagrid with columns bound to an observable collection. All works
I have a datagrid bound to an observable collection of objects. What I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.