简体   繁体   English

垂直滚动条的情况下如何在DataGridView中标记最后一行?

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

I have try MyDataGridView.Rows[index].Selected = true; 我尝试了MyDataGridView.Rows[index].Selected = true; but this marked all the rows. 但这标记了所有行。

What i want is in case of vertical scroll bar i want to see the last row without do it manually 我想要的是在垂直滚动条的情况下,我希望不手动查看最后一行

This is not working because like Selected property it mark all the rows: 这是行不通的,因为像Selected property它标记了所有行:

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

This is my add item function: 这是我的添加项目功能:

    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];
        });
    }

This function focus the last row but selected all the rows in DataGridView 此函数将焦点放在最后一行,但在DataGridView中选择了所有行

Try this: 尝试这个:

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.

相关问题 更改高度后如何调整DataGridView的垂直滚动位置以显示整个最后一行? - How to adjust vertical scroll position of DataGridView to show entire last row after changing its height? 如何从C Sharp中的DataGridView中删除垂直和水平滚动条? - How to remove Vertical and Horizontal scroll bar from DataGridView in C sharp? 如何将 DataGridView 组件的最后一行标记为只读? - How to mark as read-only the last row of a DataGridView component? 在dataGridView中更改垂直滚动条的宽度 - Changing width of vertical scroll bar in dataGridView WrapMode为true时,DataGridView滚动到最后一行 - DataGridView scroll to last row while WrapMode true 如何将所有行放入datagridview中,以使垂直滚动条不出现C#? - How to fit all rows into datagridview so vertical scroll bar doesn't appear C#? 如何使Windows窗体上的dataGridView中的最后一行始终显示,同时仍允许其余行滚动 - How to make last row in a dataGridView on a Windows Form to be displayed all the time while still allowing the remaining rows to scroll 如何增加DataGridView滚动条的宽度? - How to increase the width of a scroll bar for DataGridView? 如何查找datagridview中存在的行并将其追加到datagridview的最后一行 - How to find a row exists in datagridview and append it to the last row of the datagridview 如何为openTK gameWindow实现垂直滚动条 - How to implement a vertical scroll bar for openTK gameWindow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM