datagridview 定位到當前行的某列

知道列名,定位到當前行的某列中:(個人認爲方法一比較科學)

(1)DataGridViewCell CurrentCell=dg2.CurrentCell;//定位當前行

           if(CurrentCell !=null && CurrentCell.OwningColumn.Name=="列名") //定位當前行某列

   {

  //對選定單元進行操作

   }


(2)DataGridView curDgv = (DataGridView)sender;
            foreach (DataGridViewRow Row in curDgv.Rows)
            {
                if (Row != null)
                {
                    foreach (DataGridViewCell cell in Row.Cells)
                    {
                        if (curDgv.Columns[cell.ColumnIndex].DataPropertyName.Equals("列名"))
                        {
                            //對選定單元進行操作
                        }
                    }
                }
            }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章