日期:2014-05-17  浏览次数:20829 次

如何在dataGridView中读取int类型的数据
我的winfrom窗体 在dataGridView下面有相关数据的文本框
当单击dataGridView中某一行,下面的文本框text中显示该行的所有信息
但是就是读取不出来int型的数据
请高手指点 分用完了 所有暂时没分了 见谅
txt_xh.Text= int.Parse(dgv.SelectedRows[0].Cells["学号"].FormattedValue.ToString());
int.Parse(txt_xh.Text)=int.Parse(dgv.SelectedRows[0].Cells["学号"].FormattedValue.ToString());
这两种都有问题  
  该怎么改呢???

------解决方案--------------------
这样写,试下。
int i = dgv.rows[x].cells[fdName].value == DBNull.Value ? 0 : Convert(dgv.rows[x].cells[fdname].value);


------解决方案--------------------
txt_xh.Text= int.Parse(dgv.SelectedRows[0].Cells["学号"].Value.ToString());

------解决方案--------------------
C# code

textBox1.Text = dataGridView1["字段名", dataGridView1.CurrentCell.RowIndex].Value.ToString();

------解决方案--------------------
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
textBox1.Text =dataGridView1.Rows[dataGridView1.CurrentRow.Index ].Cells["id"].Value.ToString() ;
textBox2.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["name"].Value.ToString();
}

------解决方案--------------------
如果value不为空的话,4楼的方法可行.