ehh*_*ehh 3 c# linq datagridview winforms datagridviewrow
我正在尝试使用最大记录 ID 值获取 DataGridViewRow。我能够获得记录 ID 本身,但我需要找到该行本身。
这是我获取最大记录 ID 的代码,它工作正常:
var addedRow =
dataGridView.Rows
.Cast<DataGridViewRow>()
.Where(r => r.Cells[Glossary.RowType].Value.ToString().Equals(Glossary.RowTypeCustom))
.Select(r => Convert.ToInt(r.Cells[Glossary.RecordId].Value))
.Max();
Run Code Online (Sandbox Code Playgroud)
我试过:
.Max(r => r.Cells[Glossary.RecordId].Value);
Run Code Online (Sandbox Code Playgroud)
我不清楚如何获取行本身,所以我可以关注它:
dataGridView.CurrentCell = addedRow;
Run Code Online (Sandbox Code Playgroud)
尝试使用这个。
var addedRow =
dataGridView.Rows
.Cast<DataGridViewRow>()
.Where(r => r.Cells[Glossary.RowType].Value.ToString().Equals(Glossary.RowTypeCustom))
.OrderByDescending(r => Convert.ToInt(r.Cells[Glossary.RecordId].Value))
.FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
希望它会有所帮助。
归档时间: |
|
查看次数: |
266 次 |
最近记录: |