Solved

C# datagridview selectedrows.count problem

Posted on 2012-03-20
2
730 Views
Last Modified: 2012-03-21
Hi all,
i have a weird datagridview problem:
       private void p_GridView_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (p_GridView.SelectedRows.Count<1)
            {
                return;  
            }

this  code is used to ensure user selected a row:
the gridview is set as
multiselect=false
rowselectionmode=fullrowselect

the problem is that if there is only one row in the grid it always has a count of 0 when it should be one.

any help would be appreciated.
thanks
0
Comment
Question by:SLIMSHIM
2 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37744560
do one of these:-

if(e.RowIndex>=0)

or

if(dataGridView1.Rows[e.RowIndex].Cells.Count>0)

Reference Link:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcelleventargs.rowindex.aspx
0
 

Author Closing Comment

by:SLIMSHIM
ID: 37747937
Thanks
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

Suggested Solutions

Title # Comments Views Activity
What's the most efficient way to load up a couple of large table in C#? 5 36
Server Error 11 47
ASP.NET 5 Templates 2 65
SQL Exceptions 3 37
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

22 Experts available now in Live!

Get 1:1 Help Now