C#实现DataGridView选中行数据
C#实现获取DataGridView选中行数据
·
asset_list.Clear();
for (int i = 0; i < DataGridView2.Rows.Count; i++)
{
DataGridViewRow row = DataGridView2.Rows[i];
// 假设你的复选框列是第一列,索引为0
if (row.Cells[0].Value != null)
{
if (row.Cells[0].Value.Equals("True"))
{
string category_name = row.Cells["Column_category_name"].Value.ToString();//类目名称
string category_no = row.Cells["Column_category_no"].Value.ToString();//类目编号
string assets_no = row.Cells["Column_assets_no"].Value.ToString();//物资编号
string another_name = row.Cells["Column_another_name"].Value.ToString();//物资名称
string rfid_no = row.Cells["Column_rfid_no"].Value.ToString();//名;
string model = row.Cells["Column_model"].Value.ToString();//
string specifications = row.Cells["Column_specifications"].Value.ToString();//
string warehouse_name = row.Cells["Column_warehouse_name"].Value.ToString();//
string warehouse_no = row.Cells["Column_warehouse_no"].Value.ToString();//
string location_no = row.Cells["Column_location_no"].Value.ToString();//
string location_name = row.Cells["Column_location_name"].Value.ToString();//
string organization_name = row.Cells["Column_organization_name"].Value.ToString();//
string organization_no = row.Cells["Column_organization_no"].Value.ToString();//
string personal_name = row.Cells["Column_personal_name"].Value.ToString();//
string material_no = row.Cells["Column_material_no"].Value.ToString();//
if (string.IsNullOrEmpty(category_no))
{
category_no = " ";
}
if (string.IsNullOrEmpty(category_name))
{
category_name = " ";
}
if (string.IsNullOrEmpty(assets_no))
{
assets_no = " ";
}
if (string.IsNullOrEmpty(another_name))
{
another_name = " ";
}
if (string.IsNullOrEmpty(rfid_no))
{
rfid_no = " ";
}
if (string.IsNullOrEmpty(model))
{
model = " ";
}
if (string.IsNullOrEmpty(specifications))
{
specifications = " ";
}
if (string.IsNullOrEmpty(warehouse_name))
{
warehouse_name = " ";
}
if (string.IsNullOrEmpty(location_name))
{
location_name = " ";
}
if (string.IsNullOrEmpty(organization_name))
{
organization_name = " ";
}
if (string.IsNullOrEmpty(personal_name))
{
personal_name = " ";
}
string title = "";
if (textBox1.Text.Equals("物资编号"))
{
title = assets_no;
}
else if (textBox1.Text.Equals("分类名称"))
{
title = category_name;
}
else if (textBox1.Text.Equals("物资名称"))
{
title = another_name;
}
else if (textBox1.Text.Equals("部门名称"))
{
title = organization_name;
}
else if (textBox1.Text.Equals("责任人"))
{
title = personal_name;
}
else
{
title = textBox1.Text;
}
string write_epc = "";
//判断写入的哪个字段
if (checkBox1.Checked == true)
{
//物资编号
write_epc = WriteStr(assets_no);//不够补0,或者定义的规则
}
else if (checkBox2.Checked == true)
{
//设备编号
write_epc = WriteStr(material_no);//不够补0,或者定义的规则
}
else if (checkBox5.Checked == true)
{
//rfid
write_epc = WriteStr(rfid_no);//不够补0,或者定义的规则
}
AssetTwo asset = new AssetTwo();
asset.write_epc = write_epc;
asset.title = title;
asset.category_no = category_no;
asset.category_name = category_name;
asset.asset_no = assets_no;
asset.asset_name = another_name;
asset.rfid_no = rfid_no;
asset.model = model;
asset.specifications = specifications;
asset.warehouse_no = warehouse_no;
asset.warehouse_name = warehouse_name;
asset.location_no = location_no;
asset.location_name = location_name;
asset.organization_no = organization_no;
asset.organization_name = organization_name;
asset.personal_name = personal_name;
asset_list.Add(asset);
AddTextToRichTextBox2("获取打印机警告状态:" + row.Cells[0].Value, Color.Goldenrod);
}
}
//if (Convert.ToBoolean(row.Cells[0].Value) == true)
//{
//}
}
AddTextToRichTextBox2("选中个数:" + asset_list.Count, Color.Green);
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐


所有评论(0)