Solved

C# datagridview selectedrows.count problem

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

809 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