C# 从RadComboBox事件获取GridViewRow
我在Telerik RadGridView中有一个RadComboBox列,我想做的是,当您更改RadComboBox中的项目时,禁用GridViewRow哪里是RadComboBox;为此,我需要获取RadComboBox的父对象,但我尝试的方法无效 这是我的RadGridView代码:C# 从RadComboBox事件获取GridViewRow,c#,wpf,telerik,radgridview,C#,Wpf,Telerik,Radgridview,我在Telerik RadGridView中有一个RadComboBox列,我想做的是,当您更改RadComboBox中的项目时,禁用GridViewRow哪里是RadComboBox;为此,我需要获取RadComboBox的父对象,但我尝试的方法无效 这是我的RadGridView代码: <telerik:RadGridView x:Name="dtgResumen" VerticalAlignment="Stretch" VerticalContentAlignment="C
<telerik:RadGridView x:Name="dtgResumen" VerticalAlignment="Stretch" VerticalContentAlignment="Center" AutoGenerateColumns="False" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" FontSize="14" RowIndicatorVisibility="Collapsed" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" IsFilteringAllowed="False" GridLinesVisibility="Both" >
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn x:Name="colStatus" Header="STATUS" Width="1.3*" >
<telerik:GridViewDataColumn.HeaderCellStyle>
<Style TargetType="telerik:GridViewHeaderCell">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="#538DD5" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="FontSize" Value="12" />
</Style>
</telerik:GridViewDataColumn.HeaderCellStyle>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<telerik:RadComboBox Name="comboBoxStatus" SelectedIndex="0" SelectionChanged="comboBox_SelectionChanged" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<telerik:RadComboBox.Items>
<telerik:RadComboBoxItem Content="Activa" Foreground="Green" />
<telerik:RadComboBoxItem Content="Cancelada" Foreground="Red" />
</telerik:RadComboBox.Items>
</telerik:RadComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
这是事件中的代码:
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var combo = sender as RadComboBox;
var row = FindParent<GridViewRow>(combo);
}
private void组合框\u SelectionChanged(对象发送者,SelectionChangedEventArgs e)
{
var combo=发送方作为RadComboBox;
变量行=FindParent(组合);
}
这是FindParent代码:
public static Parent FindParent<Parent>(DependencyObject child) where Parent : DependencyObject
{
DependencyObject parentObject = child;
//We are not dealing with Visual, so either we need to fnd parent or
//get Visual to get parent from Parent Heirarchy.
while (!((parentObject is System.Windows.Media.Visual) || (parentObject is System.Windows.Media.Media3D.Visual3D)))
{
if (parentObject is Parent || parentObject == null)
return parentObject as Parent;
else
parentObject = (parentObject as FrameworkContentElement).Parent;
}
//We have not found parent yet , and we have now visual to work with.
parentObject = VisualTreeHelper.GetParent(parentObject);
//check if the parent matches the type we're looking for
if (parentObject is Parent || parentObject == null)
return parentObject as Parent;
else
//use recursion to proceed with next level
return FindParent<Parent>(parentObject);
}
公共静态父FindParent(DependencyObject子对象),其中父对象:DependencyObject
{
DependencyObject parentObject=子对象;
//我们不是在处理视觉问题,所以我们要么需要fnd parent,要么需要fnd parent
//获取视觉以从父继承权获取父。
而(!((parentObject是System.Windows.Media.Visual)| |(parentObject是System.Windows.Media.Media3D.Visual3D)))
{
if(parentObject为Parent | | parentObject==null)
将parentObject返回为父对象;
其他的
parentObject=(parentObject作为FrameworkContentElement);
}
//我们还没有找到父对象,现在我们可以使用可视化。
parentObject=VisualTreeHelper.GetParent(parentObject);
//检查父项是否与我们要查找的类型匹配
if(parentObject为Parent | | parentObject==null)
将parentObject返回为父对象;
其他的
//使用递归继续下一个级别
返回FindParent(parentObject);
}
我也尝试过这个,但不起作用:
var combo = sender as RadComboBox;
var row = combo.ParentOfType<GridViewRow>();
var combo=发送方作为RadComboBox;
var row=combo.ParentOfType();
您是否在代码隐藏中工作?如果是这样,您是否可以直接访问DGV并直接访问CurrentRow或SelectedRows(这是假设他们在网格中的组合框上工作时选中了该行)?这是格瑞苏门。CurrentRow@DavidOesterreich,CurrentRow属性不存在