datagrid height issue in nested datagrid( when using three data grid)

Posted by prince23 on Stack Overflow See other posts from Stack Overflow or by prince23
Published on 2010-05-22T04:02:29Z Indexed on 2010/05/22 4:10 UTC
Read the original article Hit count: 757

Filed under:
|

hi, i have a nested datagrid(which is of three data grid). here i am able to show data with no issue.

the first datagrid has 5 rows the main problem that comes here is when you click any row in first datagrid i show 2 datagrid( which has 10 rows)

lets say i click 3 row in 2 data grid. it show further records in third datagrid. again when i click 5 row in 2 data grid it show further records in third datagrid. now all the recods are shown fine

when u try to collpase the 3 row in 2 data grid it collpase but the issue is the height what the third datagrid which took space for showing the records( we can see a blank space showing between the main 2 datagrid and third data grid)

in every grid first column i have an button where i am writing this code for expand and collpase

this is the functionality i am implementing in all the datagrid button where i do expand collpase.

hope my question is clear . any help would great

 private void btn1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Button btnExpandCollapse = sender as Button;
                Image imgScore = (Image)btnExpandCollapse.FindName("img");
                DependencyObject dep = (DependencyObject)e.OriginalSource;
               while ((dep != null) && !(dep is DataGridRow))
                {
                    dep = VisualTreeHelper.GetParent(dep);
                }
                // if we found the clicked row 
                if (dep != null && dep is DataGridRow)
                {
                    DataGridRow row = (DataGridRow)dep;
                    // change the details visibility 
                    if (row.DetailsVisibility == Visibility.Collapsed)
                    {
                        imgScore.Source = new BitmapImage(new Uri("/Images/a1.JPG", UriKind.Relative));
                        row.DetailsVisibility = Visibility.Visible;
                    }
                    else
                    {
                        imgScore.Source = new BitmapImage(new Uri("/Images/a2JPG", UriKind.Relative));
                        row.DetailsVisibility = Visibility.Collapsed;
                        }
                    }
                }

            catch (System.Exception)
            {
            }
        }
---------------------------------------
2 datagrid
private void btn2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Button btnExpandCollapse = sender as Button;
                Image imgScore = (Image)btnExpandCollapse.FindName("img");
                DependencyObject dep = (DependencyObject)e.OriginalSource;
               while ((dep != null) && !(dep is DataGridRow))
                {
                    dep = VisualTreeHelper.GetParent(dep);
                }
                // if we found the clicked row 
                if (dep != null && dep is DataGridRow)
                {
                    DataGridRow row = (DataGridRow)dep;
                    // change the details visibility 
                    if (row.DetailsVisibility == Visibility.Collapsed)
                    {
                        imgScore.Source = new BitmapImage(new Uri("/Images/a1.JPG", UriKind.Relative));
                        row.DetailsVisibility = Visibility.Visible;
                    }
                    else
                    {
                        imgScore.Source = new BitmapImage(new Uri("/Images/a2JPG", UriKind.Relative));
                        row.DetailsVisibility = Visibility.Collapsed;
                        }
                    }
                }

            catch (System.Exception)
            {
            }
        }
 -----------------
3 datagrid
private void btn1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Button btnExpandCollapse = sender as Button;
                Image imgScore = (Image)btnExpandCollapse.FindName("img");
                DependencyObject dep = (DependencyObject)e.OriginalSource;
               while ((dep != null) && !(dep is DataGridRow))
                {
                    dep = VisualTreeHelper.GetParent(dep);
                }
                // if we found the clicked row 
                if (dep != null && dep is DataGridRow)
                {
                    DataGridRow row = (DataGridRow)dep;
                    // change the details visibility 
                    if (row.DetailsVisibility == Visibility.Collapsed)
                    {
                        imgScore.Source = new BitmapImage(new Uri("/Images/a1.JPG", UriKind.Relative));
                        row.DetailsVisibility = Visibility.Visible;
                    }
                    else
                    {
                        imgScore.Source = new BitmapImage(new Uri("/Images/a2JPG", UriKind.Relative));
                        row.DetailsVisibility = Visibility.Collapsed;
                        }
                    }
                }

            catch (System.Exception)
            {
            }
        }**

© Stack Overflow or respective owner

Related posts about silver

Related posts about silverlight-4.0