这是测试程序里的一段代码:
using (DeviceConnection dc = new DeviceConnection(deviceName))
            {
                try
                {
                    dc.Open();
                    txtPrintTagID.Clear();
                    int offset= Convert.ToInt32(txtStart.Text);
                    
                    int length= Convert.ToInt32(txtLength.Text);
                    byte[] tagId = HexUtilities.HexDecode(gridTags.Rows[0].Cells[0].Value.ToString());
                    byte[] data = dc.GetPartialTagData(tagId, seek , offset, length); 
                    txtData.Text = HexUtilities.HexEncode(data);
                  
                }
关键在这句里
byte[] tagId = HexUtilities.HexDecode(gridTags.Rows[0].Cells[0].Value.ToString());
这句的意思,是取datagridview 控件上的值,现在取的值是第一行第一列的值,
转为字节数组,做为参数的;而现在想在datagridview 上选择TAG内容,该如何做?
选那行就把那行的 第一列的TAG 给取出来,
该怎么搞
谢谢

解决方案 »

  1.   

    gridTags.Rows[SelectedIndex].Cells[0].Tag
      

  2.   

    DataGridViewCell有Tag属性..try..gridTags.Rows[0].Cells[0].Tag;
      

  3.   

    byte[] tagId = HexUtilities.HexDecode(gridTags.Rows[0].Cells[0].Value.ToString());
    现在是要第一行的数据,所以是Rows[???]应该这里的值对应某一行就想在鼠标选某行,Rows[???]里的索引变化吧
    怎么在鼠标按下,获得索引呢?上面两位兄弟的意思,没明白
      

  4.   

    private void gridTags_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
            {
                string aa;
                         aa= this.gridTags.Rows[e.RowIndex].Cells[0].FormattedValue.ToString();
            }我这样可以拉
    谢谢两位