• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

Select row from DatagridView C#

I notice when ever I click on a cell it only highlights that particular cell only...

Is there a way to make it when the user clicks on the cell it highlights the entire row?
0
csharp_learner
Asked:
csharp_learner
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Changing the SelectionMode property of the grid to FullRowSelect should do it.
0
 
RiteshShahCommented:
use this javascript code and paste it in your .aspx page.

<script language="javascript" type="text/javascript">
       
        var OldColor;
       
        function changeColor(Sender,Mouse)
        {
           
            var Color;
           if(Mouse=="Over")
            {
                OldColor=Sender.bgColor;
                Color="silver";
            }
           else
                Color=OldColor;
           
            Sender.bgColor=Color;
        }
       
        var GridOldColor;
        function GridColorChange(Sender,mouse)
        {
            if(mouse=="Over")
           {
                GridOldColor=Sender.style.backgroundColor;
                Sender.style.backgroundColor="Silver";    
           }
           else
           {
                Sender.style.backgroundColor=GridOldColor;
           }
        }
 </script>


and in your aspx.cs file, have this code

//GVProjectStatus is a name of grid.
protected void GVProjectStatus_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "GridColorChange(this,'Over');");
        e.Row.Attributes.Add("onmouseout", "GridColorChange(this,'Out');");
    }
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now