sách gpt4 ăn đã đi

c# - 说明如何使用 FirstDisplayedScrollingRowIndex

In lại 作者:太空狗 更新时间:2023-10-30 01:05:02 24 4
mua khóa gpt4 giày nike

刚刚发布,需要澄清一个属性。 (请注意,我知道这个问题与其他问题类似,因此我尝试在其他地方寻找解决方案,但找不到适合这种情况的确切解决方案)。

我是编程新手,不知道如何让 DataGridView 滚动到用户选择的行。我尝试使用 FirstDisplayedScrollingRowIndex 但出现以下错误:

Error: Cannot implicitly convert type 'System.Windows.Forms.DataGridViewRow' to 'int'

当我尝试将用户选择的行带到数据 GridView 的顶部时发生:

dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[i]

Mã hoàn chỉnh như sau:

String searchVal = textBox1.Text;

for (int i = 0; i < dataGridView1.RowCount; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null && dataGridView1.Rows[i].Cells[0].Value.ToString().Contains(searchVal))
{
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[i];
dataGridView1.Update();
}
}

câu trả lời hay nhất

根据文档,FirstDisplayedScrollingRowIndex :

Gets or sets the index of the row that is the first row displayed on the DataGridView.

您已经将索引存储在 Tôi 中……尝试使用它:

dataGridView1.FirstDisplayedScrollingRowIndex = i;

要解决您在评论中提出的第二个问题,请按照以下方法找到第一个完全匹配项(如果有):

var selectedRow = dataGridView1.Rows.Cast()
.FirstOrDefault(x => Convert.ToString(x.Cells[0].Value) == searchVal);

if (selectedRow != null)
{
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[i];
dataGridView1.Update();
}

关于c# - 说明如何使用 FirstDisplayedScrollingRowIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20356809/

24 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress