if (row.Cells[0].Value != null) { if (bool.Parse(row.Cells[0].Value.ToString())) { int row1 = row.Index; remarkid = remarkid + "" + this.dataGridView1[1, row1].Value.ToString() + "" + ","; } }
时间: 2024-02-10 17:08:51 浏览: 22
这段代码的作用是在 DataGridView 控件中,遍历每一行,判断哪些行被选中了,并将选中行的行标存储到变量 remarkid 中。具体实现是:判断当前行的第一列是否选中,如果是,则获取当前行的行号 row1,并将当前行的第二列的值(即行标)添加到 remarkid 变量中。最终,remarkid 变量中存储的是以逗号分隔的选中行的行标字符串。
相关问题
优化代码for (auto in = Iniomdl.begin(); in != Iniomdl.end(); ++in) { for (auto ic = in->lscsys.begin(); ic != in->lscsys.end(); ++ic) { if (ic->yes_or_not == 3) { ic->remove(); } } }
可以使用 `remove_if` 函数来优化代码,示例如下:
```c++
for (auto& in : Iniomdl) {
in.lscsys.erase(
std::remove_if(in.lscsys.begin(), in.lscsys.end(), [](const auto& ic){ return ic.yes_or_not == 3; }),
in.lscsys.end()
);
}
```
这里使用了 lambda 表达式来指定移除的条件,即 `ic.yes_or_not == 3`。该 lambda 表达式返回一个 bool 类型的值,如果为 true,则表示需要移除该元素。
`remove_if` 函数会将需要移除的元素移动到容器的末尾,并返回指向第一个被移除元素的迭代器。最后再使用 `erase` 函数来删除这些元素,从而达到优化代码的目的。
state: value.mgState =? 1:0 改写
可能您的意思是:将 `value.mgState` 的值转换为布尔值,然后将其转换为整数类型,1 表示 True,0 表示 False。可以使用以下方式实现:
```
state = int(bool(value.mgState))
```
其中,`bool(value.mgState)` 将 `value.mgState` 转换为布尔值,`int()` 将布尔值转换为整数类型。
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)