关于在DataGrid如何提取每行的绑定的Tag值(取Tag的目地是为了进行某些操作)

这个问题都快想疯了。。。。最后出去逛了一圈,回来之后瞎写居然写出来了。

 ObservableCollection<DataArraly> list = new ObservableCollection<DataArraly>();
 //首先简单介绍一下我绑定List,关于这个我本人前面的博客有具体讲
  list.Add(new DataArraly() { ID = "1", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "1", Color = "Cyan(ABS1)" });//
  list.Add(new DataArraly() { ID = "2", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "2", Color = "Orange(ABS2)" });//
  list.Add(new DataArraly() { ID = "3", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "3", Color = "Green(ABS3)" });//
  list.Add(new DataArraly() { ID = "4", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "4", Color = "Blue(ABS4)" });//
  list.Add(new DataArraly() { ID = "5", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "5", Color = "Purple(ABS5)" });//
  list.Add(new DataArraly() { ID = "6", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "6", Color = "Brown(ABS6) " });//
  list.Add(new DataArraly() { ID = "7", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "7", Color = "Black(ABS7)" });//
  list.Add(new DataArraly() { ID = "8", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "8", Color = "Gray(ABS8)" });//
  list.Add(new DataArraly() { ID = "9", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "9", Color = "OrangeRed(ABS9)" });//
  list.Add(new DataArraly() { ID = "10", Remark = " * ", Type = "Absorbance", Xunits = "nm", FID = "10", Color = "MediumSpringGreen(ABS10)" });// 

前端代码一部分

   <DataGridTemplateColumn Header="View" Width="0.7*">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <CheckBox Click="CheckBox_Click" Tag="{Binding FID, Mode=TwoWay}" Name="checkbox_1" IsChecked="True"></CheckBox>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>

我的Tag是绑定了FID,为了实现某种功能,我必须在选中表格的某行时提取到这个“FID”值。
例如下表,我要提取4这行我绑定的标签值FID
在这里插入图片描述
代码具体如下,大概的想法:我选中这行时得到List的下标,然后根据下标得到数组List中关于FID的值。
***list[_rowIndex].FID==(object) “4”***这句是核心

 private void Remove_Line_Click(object sender, RoutedEventArgs e)
        {
            int _rowIndex = 0;
            int _columnIndex = 0;
            if (GetCellXY(DataGrid_Measure2, ref _rowIndex, ref _columnIndex))
            {          
               if ( list[_rowIndex].FID==(object) "4")//这一句就找到了我绑定的Tag值FID
                {
                    this.ShowDemarcatezedGraph.GraphPane.CurveList.Remove(ABS1);                   
                    ShowDemarcatezedGraph.AxisChange();
                    ShowDemarcatezedGraph.Refresh();
                }
            }
        }
        private bool GetCellXY(DataGrid dg, ref int rowIndex, ref int columnIndex)
        {
            var _cells = dg.SelectedCells;//获取选中单元格的列表         
            if (_cells.Any())
            {
                rowIndex = dg.Items.IndexOf(_cells.First().Item);
                columnIndex = _cells.First().Column.DisplayIndex;
                return true;
            }
            return false;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值