Dobleclick在Datagrid中的单元格上 [英] Dobleclick on a cell in Datagrid

查看:67
本文介绍了Dobleclick在Datagrid中的单元格上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计,


实施ha dtagrid的应用程序我遇到了以下问题:


我必须加入双击特定小区上的活动。 我在datagrid描述中使用声明尝试了id:


MouseDoubleClick =" DataGridTasks_MouseDoubleClick" >


或带有样式:


< DataGrid.Resources>

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < Style TargetType =" {x:Type DataGridCell}">

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < EventSetter Event =" MouseDoubleClick" Handler =" DataGridCell_MouseDoubleClick" />

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / Style>

< /DataGrid.Resources>



两者都可以确定指数行很简单:


private void DataGridTasks_MouseDoubleClick(object sender,MouseButtonEventArgs e)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DataGrid Grid =(DataGrid)发件人;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; int Index = Grid.SelectedIndex;


}


但是我现在只能通过标题确定点击的那个:


DataGridCell dataGridCellTarget =(DataGridCell)sender;

string ColHeader = dataGridCellTarget.Column.Header.ToString();


Is有没有办法找出列的绑定或名称?


Thanx很多提前!


Carsten







解决方案

Hi Carsten,


根据你的描述,如果双击特定单元格,你想从DataGrid获取列标题,我是对的吗?


如果是,你可以拿一个看下面的代码,我可以在DatGridCell_mousedoubleclick事件中获得列标题。

< DataGrid.Resources> 
< Style TargetType =" {x:Type DataGridCell}">
< EventSetter Event =" MouseDoubleClick"处理机= QUOT; DataGridCell_MouseDoubleClick" />
< / Style>
< /DataGrid.Resources>



 private void DataGridCell_MouseDoubleClick(object sender,MouseButtonEventArgs e)
{
DataGridCell dataGridCellTarget =(DataGridCell)sender;
// TODO:你的逻辑在这里
string ColHeader = dataGridCellTarget.Column.Header.ToString();
}

最好的问候,


Cherry



Hi Folks,

wihle implementig an applicatio wit ha dtagrid I ran into following problem:

I have to cath the doubleclick event on a specific cell.  I tried id with the declaration in the datagrid description:

MouseDoubleClick="DataGridTasks_MouseDoubleClick" >

or with a style:

<DataGrid.Resources>
                <Style TargetType="{x:Type DataGridCell}">
                    <EventSetter Event="MouseDoubleClick" Handler="DataGridCell_MouseDoubleClick"/>
                </Style>
</DataGrid.Resources>

Both work OK an detemining the Index of the row is easy:

private void DataGridTasks_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGrid Grid = (DataGrid)sender;
            int Index = Grid.SelectedIndex;

}

But frt the coulmn I am currently only able to determine the clicked one by the header:

DataGridCell dataGridCellTarget = (DataGridCell)sender;
string ColHeader = dataGridCellTarget.Column.Header.ToString();

Is there any way to find out the Binding or Name of the column?

Thanx a lot in Advance!

Carsten


解决方案

Hi Carsten,

According to your description, you want to get column header from DataGrid if you double click specific cell, am I right?

If yes, you can take a look the following code, I can get column header in DatGridCell_mousedoubleclick event.

  <DataGrid.Resources>
                <Style TargetType="{x:Type DataGridCell}">
                    <EventSetter Event="MouseDoubleClick" Handler="DataGridCell_MouseDoubleClick"/>
                </Style>
            </DataGrid.Resources>


 private void DataGridCell_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridCell dataGridCellTarget = (DataGridCell)sender;
            // TODO: Your logic here
            string ColHeader = dataGridCellTarget.Column.Header.ToString();
        }

Best Regards,

Cherry


这篇关于Dobleclick在Datagrid中的单元格上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆