Solved

C# datagridview selectedrows.count problem

Posted on 2012-03-20
2
791 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

635 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