我选中DATAGRIDVIEW其中的一行`````````怎么获取这一行的主键的值是多少。。请大家把自己的方法说说。。dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value我是这样写的。不过第一次是正确的。在来一次的话,,他返回的值还是第一次得到的值谢谢

解决方案 »

  1.   

    他的索引和dateset 的table的索引是一样的
      

  2.   

    这样呢:dataGirdClientAllMEssage.Rows[dataGirdClientAllMEssage.SelectedIndex].Cells["SerialNO"].Text.Trim
      

  3.   

    dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value.ToString();
      

  4.   

    dategrid.currentrowindex   你用的是datagrid吧,我的事vs2005datagridview没有这个索引.dataGirdClientAllMEssage.Rows[dataGirdClientAllMEssage.SelectedIndex].Cells["SerialNO"].Text.Trim
    中间的SelectedIndex.我没有点出来这个属性.dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value.ToString();
    取出来的值,还是第一次的值.大家还有没有什么方法阿..请说说看...
      

  5.   

    抱歉,没有说明白;我说的.SelectedIndex是ASP.NET中的GridView中的!你说的是winform?
    是不是WEB和Winform的GridView不一样啊!
      

  6.   


    写法应该正确
    dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value但你是在什么情况下 取 dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value 值的呢
    如果当前行确实没有改变,当然返回的值还是第一次得到的值了。可以试一下,把他放在 DATAGRIDVIEW 的 Click 事件中测一下 ,我想不会错的。
      

  7.   

    winform中我用了你语句了:dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value.ToString();显示的正确的啊,选择那行得到那个主键值吗!代码跟进去看一下吧,是不是中间出了异常或者你的事件没有触发啊!
      

  8.   

    写法应该正确
    dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value.ToString()但你是在什么情况下 取 dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value.ToString() 值的呢
    如果当前行确实没有改变,当然返回的值还是第一次得到的值了。可以试一下,把他放在 DATAGRIDVIEW 的 Click 事件中测一下 ,我想不会错的。
    不好意思,刚才粘贴疏忽,少了 .ToString()
      

  9.   

    这个放在datagridview事件里我还没有试过.
    是vs2005 winform   我也没有说清楚..这个问题我最后绕过去了..用另外的方法解决掉了..但是这个问题我依然在看,就像dataGirdClientAllMEssage.CurrentRow.Cells["SerialNO"].Value.ToString()这个条语句,我跟了很多次,依然显示的是datagridview中第一条数据的地   SerialNO字段的值
    大家不要这么客气,呵呵。学习学习,我算是个新手。。
      

  10.   

    DataGridView.SelectedRows.rows[0].Cells...
    试试,
      

  11.   

    这样取可能会好点喔:dataGridView1.Rows[dataGridView1.CurrentCellAddress.Y].Cells["字段名"].Value如果有什么不好的地方,还请不要打击我...