private void dgvContent_SelectionChanged(object sender, EventArgs e)
        {
            //clear selected items
            this._selecteditems.Clear();
            //multi select controls            bool Verify = true;
            bool Antiverify = true;
            foreach (DataGridViewRow row in dgvContent.SelectedRows)
            {
                int agencyid = int.Parse(dgvContent.Rows[dgvContent.CurrentRow.Index].Cells["agency_sn"].Value.ToString());
                int subjectid = int.Parse((dgvContent.Rows[dgvContent.CurrentRow.Index].Cells["account_subject"].Value.ToString()));
                
                DataSet ds = PeerPayableFilter.GetRow(subjectid, agencyid);                dgvPeerPay.DataSource = ds.Tables[0];
            }
}一到这里就报错 int.Parse(dgvContent.Rows[dgvContent.CurrentRow.Index].Cells["agency_sn"].Value.ToString());Cells["agency_sn"].Value内容为空??求解

解决方案 »

  1.   

      foreach (DataGridViewRow row in dgvContent.SelectedRows)
                {
                    int agencyid = int.Parse(dgvContent.Rows["xx"].Cells["agency_sn"].Value.ToString());
                    int subjectid = int.Parse((dgvContent.Rows["xx"].Cells["account_subject"].Value.ToString()));
                    
                    DataSet ds = PeerPayableFilter.GetRow(subjectid, agencyid);                dgvPeerPay.DataSource = ds.Tables[0];
                }
    }
      

  2.   

    Rows有"Rows["XX"]"这个属性吗??
      

  3.   

    for (int i = 0 ; i < dgvContent.SelectedRows.count; i++)
    {
        DataGridViewRow row = dgvContent.SelectedRows[i];
        int agencyid = int.Parse(dgvContent.SelectedRows[i].Cells["agency_sn"].Value.ToString());
    }
    这样试试
      

  4.   

    错误有两方面的原因
    1、Value.ToString() 如果这个Value为Null  则不能 调用 ToString()方法
    2、int.Parse(string str) 要看这个 str 能否转换为 int ,要注意规则 建议你查下  你这个程序还有另一个方面的问题 foreach (DataGridViewRow row in dgvContent.SelectedRows)
                {
                    int agencyid = int.Parse(dgvContent.Rows[dgvContent.CurrentRow.Index].Cells["agency_sn"].Value.ToString());
                    int subjectid = int.Parse((dgvContent.Rows[dgvContent.CurrentRow.Index].Cells["account_subject"].Value.ToString()));
                    
                    DataSet ds = PeerPayableFilter.GetRow(subjectid, agencyid);                dgvPeerPay.DataSource = ds.Tables[0];
                }
    //从你的程序来个 你应该只允许 用户选择 dgv 中的一行 就没有必要遍历 SelectRows了 直接用 CurrentRow
      

  5.   

    解决了,自己的问题DataGridView里没有指定字段