?
Solved

How to select a specific cell in DataGridView

Posted on 2006-07-04
3
Medium Priority
?
625 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 1400 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

765 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