Solved

C# datagridview selectedrows.count problem

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

14 Experts available now in Live!

Get 1:1 Help Now