Telerik Radgrid WPF

发布于 2024-08-18 11:30:03 字数 284 浏览 11 评论 0原文

我的 WPF 页面有 Telerik 提供的 RadGrid 控件。网格是一个嵌套网格,本质上意味着单击该行最左边列上的 (+) 符号会将行展开为子网格。这是通过在我的 XAML 中指定分层网格来完成的。当您单击该行并展开子网格时,一切正常,但最初选定行的 selectedItem 似乎没有改变。例如,最初选择网格的第 1 行,然后展开第 4 行以显示子网格。子网格已显示,但 selectedItem 仍为第 1 行。所需的行为是,一旦展开以显示子网格,第 4 行将成为 selectedItem。谁能指出这里到底出了什么问题。

谢谢

My WPF page has a RadGrid control provided by Telerik. The Grid is a nested grid which essentially means that clicking on the (+) sign on the leftmost column of the row expands the row into a Subgrid. This is being done by specifying a hierarchical grid in my XAML. Everything works just fine when you click on the row and expand the subgrid but the selectedItem of the initially selected row does not seem to change. An example would be selecting row 1 of the grid initially and then expanding row 4 to display the subgrid. The subgrid is displayed but the selectedItem is still row 1. The desired behavior is for row 4 to be the selectedItem once it is expanded to display the subgrid. Can anyone point out what exactly is going wrong over here.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

同展鸳鸯锦 2024-08-25 11:30:03

你是对的 - 这是更新版本:

    private void RadGridView_Loaded(object sender, RoutedEventArgs e)
    {
        var childGrid = (RadGridView)sender;
        var parentRow = childGrid.ParentRow;

        if (parentRow != null)
        {
            RadGridView1.SelectedItem = childGrid.DataContext;
            parentRow.IsExpandedChanged += new RoutedEventHandler(parentRow_IsExpandedChanged);
        }
    }

    void parentRow_IsExpandedChanged(object sender, RoutedEventArgs e)
    {
        RadGridView1.SelectedItem = ((GridViewRow)sender).DataContext;
    }

Your are right - here is the updated version:

    private void RadGridView_Loaded(object sender, RoutedEventArgs e)
    {
        var childGrid = (RadGridView)sender;
        var parentRow = childGrid.ParentRow;

        if (parentRow != null)
        {
            RadGridView1.SelectedItem = childGrid.DataContext;
            parentRow.IsExpandedChanged += new RoutedEventHandler(parentRow_IsExpandedChanged);
        }
    }

    void parentRow_IsExpandedChanged(object sender, RoutedEventArgs e)
    {
        RadGridView1.SelectedItem = ((GridViewRow)sender).DataContext;
    }
饮惑 2024-08-25 11:30:03

这是一个示例:

XAML

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"    
Title="Window1">
<Grid>
    <telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding}">
        <telerik:RadGridView.ChildTableDefinitions>
            <telerik:GridViewTableDefinition  />
        </telerik:RadGridView.ChildTableDefinitions>
        <telerik:RadGridView.HierarchyChildTemplate>
            <DataTemplate>
                <telerik:RadGridView ItemsSource="{Binding Items}" Loaded="RadGridView_Loaded" />
            </DataTemplate>
        </telerik:RadGridView.HierarchyChildTemplate>
    </telerik:RadGridView>
</Grid>

C#

using System.Windows;
using System.Linq;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            DataContext = from i in Enumerable.Range(0, 10)
                          select new
                          {
                              ID = i,
                              Items = from j in Enumerable.Range(0, 10)
                                      select new
                                      {
                                          ID = j,
                                      }
                          };
        }

        private void RadGridView_Loaded(object sender, RoutedEventArgs e)
        {
            RadGridView1.SelectedItem = ((FrameworkElement)sender).DataContext;
        }
    }
}

Here is an example:

XAML

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"    
Title="Window1">
<Grid>
    <telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding}">
        <telerik:RadGridView.ChildTableDefinitions>
            <telerik:GridViewTableDefinition  />
        </telerik:RadGridView.ChildTableDefinitions>
        <telerik:RadGridView.HierarchyChildTemplate>
            <DataTemplate>
                <telerik:RadGridView ItemsSource="{Binding Items}" Loaded="RadGridView_Loaded" />
            </DataTemplate>
        </telerik:RadGridView.HierarchyChildTemplate>
    </telerik:RadGridView>
</Grid>

C#

using System.Windows;
using System.Linq;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            DataContext = from i in Enumerable.Range(0, 10)
                          select new
                          {
                              ID = i,
                              Items = from j in Enumerable.Range(0, 10)
                                      select new
                                      {
                                          ID = j,
                                      }
                          };
        }

        private void RadGridView_Loaded(object sender, RoutedEventArgs e)
        {
            RadGridView1.SelectedItem = ((FrameworkElement)sender).DataContext;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文