Solved

How to select a specific cell in DataGridView

Posted on 2006-07-04
3
622 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
C# Gridview 1 66
orderby list (from Json) 1 32
Build a string of emails from a gridview 2 20
ASP.NET data base connection 35 46
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 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