DataGridview中的行边框 [英] Row Border in DataGridview

查看:50
本文介绍了DataGridview中的行边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请参阅我的代码

Hi All,
Please see my code

private void DrawingList_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
            {
                if (DrawingList.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected == true)
                {
                    e.Paint(e.CellBounds, DataGridViewPaintParts.All & ~DataGridViewPaintParts.Border);
                    using (Pen p = new Pen(Color.Red, 1))
                    {
                        System.Drawing.Rectangle rect = e.CellBounds;
                        rect.Width -= 2;
                        rect.Height -= 2;
                        e.Graphics.DrawRectangle(p, rect);
                    }
                    e.Handled = true;
                }
            }
        }



我用它来突出显示Datagridview中的选定单元格(Name is Drawinglist)。但现在我想要突出显示整行(请注意我的选择模式是单格)。我怎么能这样做......这是可能的吗?

谢谢,

Manu


I used this to highlight the selected cell in a Datagridview(Name is Drawinglist).But Now I want to highlight the entire Row (Please note that my selection mode is single cell).How can I do that...Is that is possible??
Thanks,
Manu

推荐答案

我只是解决了这个问题,但请随意添加更好的答案。

这是我的代码。 />
HI all I solved that but please feel free to add any answer better than this.
this is my codes.
private void DrawingList_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
            {
                if (DrawingList.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected == true)
                {
                    e.Paint(e.CellBounds, DataGridViewPaintParts.All & ~DataGridViewPaintParts.Border);
                    using (Pen p = new Pen(Color.Blue, 1))
                    {
                        System.Drawing.Rectangle rect = e.CellBounds;
                        rect.Width -= 2;
                        rect.Height -= 2;
                        e.Graphics.DrawRectangle(p, rect);
                    }
                    e.Handled = true;
                }

                if (DrawingList.SelectedCells.Count>0)
                {
                    if (e.RowIndex == DrawingList.SelectedCells[0].RowIndex)
                    {
                        e.Paint(e.CellBounds, DataGridViewPaintParts.All & ~DataGridViewPaintParts.Border);
                        using (Pen p = new Pen(Color.Blue, 1))
                        {
                            System.Drawing.Rectangle rect = e.CellBounds;
                            rect.Height -= 2;
                            e.Graphics.DrawRectangle(p, rect);
                        }
                        e.Handled = true;
                    }
                }

                
            }
        }






and

private void DrawingList_SelectionChanged(object sender, EventArgs e)
{
    if (DrawingList.SelectedCells.Count > 0)
    {
       DrawingList.Invalidate();
    }
}



快乐编码!!


Happy coding!!


这篇关于DataGridview中的行边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆