c# - 带复选框的 ListView 获取选定的行索引

标签 c# wpf listview checkbox

这是我的问题,我有一个带复选框的 ListView ,我想获取所选行的索引 我想获取行的索引以在验证后禁用此行

我尝试不同的方法

CheckBox cbx = sender as CheckBox.tag;
    if (cbx != null) {
        var index = cbx.Tag.ToString();
    }
(((ContentPresenter)((CheckBox)sender).TemplatedParent)).IsEnabled = false; with this i disable just the checkbox 

CheckBox cbx = sender as CheckBox.tag;
int index = (int)(sender as CheckBox).Tag;

最佳答案

一行使用下面的代码:

int index = YourListView.SelectedIndex;

关于c# - 带复选框的 ListView 获取选定的行索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30914244/

相关文章:

c# - 读/写 'Extended' 文件属性 (C#)

c# - 将 C++ 库嵌入 .Net 库

c# - WPF - 从代码隐藏/附加行为绑定(bind)到显式实现的接口(interface)属性

wpf - 去掉tab控件那个tab下的那一行

c# - 在数据网格中绑定(bind)枚举属性的最佳方法

android - 如何调用 ListView 中的按钮单击?

c# - 使用按键触发 Blazor 中的按钮时未设置对象引用

C# 3.0 泛型类型推断 - 将委托(delegate)作为函数参数传递

android - 从 ListView fragment 中单击特定项目时如何使用 webview 打开 fragment 中的链接

android - 如何删除列表查看所有项目