Solved

Select row from DatagridView C#

Posted on 2009-04-14
2
614 Views
Last Modified: 2013-12-17
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
Comment
Question by:csharp_learner
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 24136121
Changing the SelectionMode property of the grid to FullRowSelect should do it.
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24136141
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A short film showing how OnPage and Connectwise integration works.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now