Strange behaviour when collapsing lines in XML bound WPF Datagrid

Posted by Flossn on Stack Overflow See other posts from Stack Overflow or by Flossn
Published on 2014-06-13T09:02:35Z Indexed on 2014/06/13 9:25 UTC
Read the original article Hit count: 186

Filed under:
|
|
|
|

i am using a wpf datagrid with a xml file as DataContext. All working good except for iterating thorough the table and collapsing individual rows. There are several checkboxes where the user can decide which kinds of rows he wants to see, dependent on their error level string.

If a checkbox is checked, some of the rows are collapsed, others not. You need to uncheck the checkbox and check it again to collapse the ones of the first try and some of the others. If you recheck it again more rows are collapsed every time. I guess it has something to do with how much of the list is actually visible and how much not because of the window size.

Thanks in advance.

foreach (DataGridRow r in rows)
        {
            bool showRow = true;

                var tb = Datagrid.GetCell(dataGridEvents, r, 2).Content;
                string level = ((TextBlock)tb).Text;

                switch (level)
                {
                    case "Warning":
                        showRow = checkBoxWarnings.IsChecked.HasValue ? checkBoxWarnings.IsChecked.Value : false;
                        break;
                    case "Critical":
                        showRow = checkBoxCritical.IsChecked.HasValue ? checkBoxCritical.IsChecked.Value : false;
                        break;
                    case "OK":
                        showRow = checkBoxOK.IsChecked.HasValue ? checkBoxOK.IsChecked.Value : false;
                        break;
                    case "Unknown":
                        showRow = checkBoxUnknown.IsChecked.HasValue ? checkBoxUnknown.IsChecked.Value : false;
                        break;
                }                
            r.Visibility = showRow ? Visibility.Visible : Visibility.Collapsed;
        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml