Solved

How to select a specific cell in DataGridView

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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