Solved

How to select a specific cell in DataGridView

Posted on 2006-07-04
3
623 Views
Last Modified: 2012-05-05
I have two DataGridViews side by side with the same number of rows and columns. They connect to untyped DataSets. When I select a specific sell in the left DataGridView, I want the same cell to be selected in the right DataGridView. How do I go about doing that?


Thanks!
0
Comment
Question by:krupini
[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
3 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 17038368
Hi krupini,
----------

in the cell content click event you can get the dgv.CurrentCell object
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcell.aspx

which would be something along the lines of
this.dataGridView2.CurrentCell = this.dataGridView1.CurrentCell;

----------
bruintje
share what you know, learn what you don't
0
 
LVL 5

Accepted Solution

by:
nickhoggard earned 350 total points
ID: 17038399
Hi,

By the same cell, do you mean the cell in the same location or the cell that contains the same piece of data?

If you are after selecting the same location then the following should help you:

       private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) {
            DataGridViewCell cell = dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];
            // Could be null if there is a different amout of data in datagridview1 than datagridview2
            if (cell != null) {
                dataGridView2.CurrentCell = cell;
            }
        }

Cheers

Nick
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17038421
Nicks way would be better indeed you probably can't just assign currentcells over gridviews :)))

didn't test that getting a bit tired over here ;)
0

Featured Post

Industry Leaders: 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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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.

688 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