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 8567949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:59:48+00:00 2026-06-11T17:59:48+00:00

I have an application that needs to display a set of rows that is

  • 0

I have an application that needs to display a set of rows that is filtered by some external criteria. For reasons I won’t explain here, I don’t really want to remove the rows from the DataTable the DataGrid is bound to. To filter the list, I am collapsing the rows that I don’t want to show. This works great, until the user sorts the DataGrid. After the sort has been completed, the collapsed rows are suddenly visible again. I looked for an Sorted event so that I could just re-collapse the rows I needed, but there is only a Sorting event. I tried to use the IsVisibleChanged on each DataGridRow, but this doesn’t seem to be firing. How do I resolve this issue?

Here is a simple demo of the problem:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        DataTable table = new DataTable();
        table.Columns.Add("Column 1");

        DataRow row = table.NewRow();
        row[0] = "1";
        table.Rows.Add(row);

        row = table.NewRow();
        row[0] = "2";
        table.Rows.Add(row);

        row = table.NewRow();
        row[0] = "3";
        table.Rows.Add(row);

        _grid.ItemsSource = table.AsDataView();
        _grid.DataContext = table;
        _grid.Loaded += _grid_Loaded;
    }

    void _grid_Loaded(object sender, RoutedEventArgs e)
    {
        var dataGridRow = GetRow(_grid, 1);
        dataGridRow.Visibility = Visibility.Collapsed;

        dataGridRow = GetRow(_grid, 0);
        dataGridRow.Visibility = Visibility.Collapsed;
    }

    public DataGridRow GetRow(DataGrid grid, int index)
    {
        var row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
        if (row == null)
        {
            // May be virtualized, bring into view and try again.
            grid.UpdateLayout();
            if (grid.Items.Count > index)
            {
                grid.ScrollIntoView(grid.Items[index]);
                row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
            }
        }
        return row;
    }
}

Here is the XAML:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <DataGrid HorizontalAlignment="Left" Margin="54,43,0,0" VerticalAlignment="Top" Height="216" Width="382" Name="_grid"/>

</Grid>

After running the program, you will see a DataGrid with only the number 3. Click “Column 1” to sort by the column, notice you now have the number 1, 2, and 3.

Any help solving this problem will be greatly appreciated.

  • 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-06-11T17:59:49+00:00Added an answer on June 11, 2026 at 5:59 pm

    I think you should be concentrating on filtering the DataTable rather than the DataGridView. Have you tried using DataView’s in the past? You can use these to filter your DataTable and as you have a bound DataGridView the View will reflect through in the GridView?

    By filtering the DataTable, you are not removing any rows, your simply altering the way it looks temporarily.

    Here’s a link that may help :-

    http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter.aspx

    I hope this helps.

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

Sidebar

Related Questions

I have an ExtJS application that needs to display an html document within a
I have a Silverlight application that needs to display data in both English (feet,
I have a Rails 3 application that needs to display images from another application.
We have a GWT application that needs to display various holidays. Is there a
I have an application that needs to display a grid of data consisting mostly
I have an application that needs to copy, remove, modify, etc. files in the
I have an application that needs updating constantly. I would like to create a
I have an application that needs to work with a vendor-supplied API to do
I have an application that needs to check a website feed every second. Sometimes
I have an application that needs to highlight individual pixels on an image. I

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.