[英]convert datagridview value to int
我正在从datagridview
单元格中获取值,如下所示,我首先将该值转换为int
我使用了'Convert.ToInt32',并且出现错误提示
输入的字符串格式不正确。
我搜索后发现必须使用int.tryParse
ImgId = Int32.TryParse(DGV_PatientImages.Rows[RowIndex].Cells[4].Value, out ImgId);
但我说错了
最佳重载方法匹配'int.TryParse(string,out int)'有一些无效的参数
int ImgId = 0;
所以我尝试向用户(int)指定的转换无效
ImgId = (int)DGV_PatientImages.Rows[RowIndex].Cells[4].Value;
我得到了
指定的演员表无效
DataGridViewRow dgvrow = DGV_PatientImages.CurrentRow;
if (dgvrow.Cells["DGV_PatientImages_ID"].Value != DBNull.Value)
{
ImgId = Convert.ToInt32(DGV_PatientImages.Rows[RowIndex].Cells[4].Value);
}
任何建议请
DGV_PatientImages.Rows[RowIndex].Cells[4].Value
是不能转换为int的类型。 它不是字符串。
通过以下代码行,您可以简单地获取其类型:
string type = DGV_PatientImages.Rows[RowIndex].Cells[4].Value.GetType().ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.