Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Please see my code
C#
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;
                }
            }
        }

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
Posted
Updated 25-Nov-14 19:24pm
v2
Comments
[no name] 26-Nov-14 0:22am    
Why dont you do that by writing it in ResourceDictionary instead of this event
Manu Prasad 26-Nov-14 0:31am    
How I can use ResourceDictionary in Windows Form Application ?.Can you explain because I am a beginner in C#.

1 solution

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
C#
private void DrawingList_SelectionChanged(object sender, EventArgs e)
{
    if (DrawingList.SelectedCells.Count > 0)
    {
       DrawingList.Invalidate();
    }
}

Happy coding!!
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900