簡體   English   中英

垂直滾動條的情況下如何在DataGridView中標記最后一行?

[英]How to mark last row in DataGridView in case of vertical scroll bar?

我嘗試了MyDataGridView.Rows[index].Selected = true; 但這標記了所有行。

我想要的是在垂直滾動條的情況下,我希望不手動查看最后一行

這是行不通的,因為像Selected property它標記了所有行:

        int last = DataGridView.Rows.Count;
        last = DataGridView.FirstDisplayedScrollingRowIndex;

這是我的添加項目功能:

    private void AddToDataGridView(MyObject obj)
    {
        this.Invoke((MethodInvoker)delegate
        {
            int index = dataGridView.Rows.Add(
                obj.machineIpAddress,
                obj.fileSize,
                obj.fileName,
                obj.processId,
                DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"),
                "Start...");
            dataGridView.Rows[index].Cells[5].Style.BackColor = Color.SkyBlue;
            ColorRow(index, obj.fileSize);
            dataGridView.CurrentCell.Selected = false;
            var lastRow = dataGridView.Rows[dataGridView.Rows.Count - 1];
            lastRow.Selected = true;
            dataGridView.FirstDisplayedCell = lastRow.Cells[0];
        });
    }

此函數將焦點放在最后一行,但在DataGridView中選擇了所有行

嘗試這個:

dataGridView1.CurrentCell.Selected = false;
var lastRow = dataGridView1.Rows[dataGridView1.Rows.Count - 1];
//de-select the last selected rows;
dataGridView1.SelectedRows.OfType<DataGridViewRow>().ToList().ForEach(x=>x.Selected=false);
lastRow.Selected = true;
dataGridView1.FirstDisplayedCell = lastRow.Cells[0];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM