WPF Datagrid:在用户双击的行中读取一个隐藏的单元格值 [英] WPF Datagrid: reading a hidden cell value in the row the user double clicked

查看:115
本文介绍了WPF Datagrid:在用户双击的行中读取一个隐藏的单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在缓慢地构建我的第一个WPF应用程序,因此请耐心等待.我已经被这个卡住了一段时间了,所以我希望CP的某个人可以帮助我.

我有一个数据网格,当用户双击它时,我想读取存储在具有已知索引的列中的唯一ID.使用本文: http://www .scottlogic.co.uk/blog/colin/2008/12/wpf-datagrid-detecting-clicked-cell-and-row/ [

Hi all!

I am very slowly building my first WPF application, so please be patient. I have been stuck with this one for a while now, so I hope someone here at CP can help me.

I have a data grid, when the user double clicks on it, i want to read a unique id that is stored in a column with a known index. Using this article: http://www.scottlogic.co.uk/blog/colin/2008/12/wpf-datagrid-detecting-clicked-cell-and-row/[^] I have written the following code, which works allright:

'find datagridcell the user double clicked
dep = DirectCast(e.OriginalSource, DependencyObject)
Do While Not dep Is Nothing
    dep = VisualTreeHelper.GetParent(dep)
    If TypeOf (dep) Is DataGridCell Then
        'find datagridcellspanel to which the datagridcell belongs
        Do While Not dep Is Nothing
            dep = VisualTreeHelper.GetParent(dep)
            If TypeOf (dep) Is DataGridCellsPanel Then
                'find cell in position 1 --> contains the id
                dgc = DirectCast(VisualTreeHelper.GetChild(dep, 1), DataGridCell)
                lId = CLng(DirectCast(dgc.Content, TextBlock).Text.ToString)
                MsgBox("id i'm looking for: " & lId.ToString)
                Exit Do
            End If
        Loop
        Exit Do
    End If
Loop



现在,如果隐藏包含ID的列,则此代码将无法工作...我了解这是因为我正在使用可视树...我应该改为使用逻辑树吗?我已经尝试过,但是datagridcell的父对象什么都不是.

那么,您知道如何执行此操作吗?我不需要编写代码,只要知道应该使用哪个类即可.也欢迎使用C#代码.

TIA为您提供帮助



Now, if the column containing the id is hidden, this code will not work... I understand that this is because I am using the Visual Tree... Should I use the logical tree instead? I have tried to, but the parent of the datagridcell is nothing.

So, any idea how to do this? I don''t need code as much as an idea of what class should I use. C# code is welcome too.

TIA for your help

推荐答案

是否 ^ ]帮助?由于null (Nothing)问题,它获取基础数据源数据.不幸的是,它在C#中,但是您应该可以遵循.
Does this[^] help? It gets the underlying data source data because of the null (Nothing) problems. It''s in C#, unfortunately but you should be able to follow.


这篇关于WPF Datagrid:在用户双击的行中读取一个隐藏的单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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