Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# datagridview selectedrows.count problem

Posted on 2012-03-20
2
Medium Priority
?
820 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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