473,322 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

DataGridView Loop Issue

Hi all,



I have used the below to display the cell content of the datagridview cell the user clicked on.



However, the MessageBox is displayed twice.



Why is this?



Expand|Select|Wrap|Line Numbers
  1.  
  2. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  3. {
  4.   DataGridView dgv = sender as DataGridView;
  5.  
  6.   if ((e.RowIndex != -1) && (e.ColumnIndex != -1))
  7.   {
  8.       if (e.ColumnIndex == 10) // 11th column
  9.       {
  10.           DataRow dr = ((DataRowView)dgv.Rows[e.RowIndex].DataBoundItem).Row;
  11.           int myCorpID = (int)dr[dgv.Columns[e.ColumnIndex].DataPropertyName];
  12.           MessageBox.Show("test"+myCorpID.ToString());
  13.        }
  14.  
  15.    }
  16. }
  17.  
  18.  
May 9 '07 #1
0 915

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: WayDownUnder | last post by:
I have a datagridview that is bound to a cutom collection. The classes contained in the custom collection have the properties that are bound to the class . This works fine ! But if one of the...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
7
by: steve | last post by:
Hi All I urgently need help on setting datagridview cell borders at runtime I found some code on the web from Programming Smart Client Data Applications with .NET 2.0 by Brian Noyes See...
2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
2
by: =?Utf-8?B?VG9jbw==?= | last post by:
Hello. My goal is to pain the entire row fore color as Red. If the value of column 24 is true (boolean), I wish to paint the row as Red. Otherwise, leave row as default (no formatting). The...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
3
by: Tony K | last post by:
VB 2005 - Windows Vista I have a form that seems to lock up when the number of rows exceed the height of the datagridview. The following code executes when data is received through the serial...
6
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab...
6
by: Ciaran | last post by:
I'm having a really strange issue with the DataGridView control in a VS2008 / .NET 3.5 winforms project. I have a simple form with a grid. In the form constructor I call a function to bind the grind...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.