Solved

How to select a specific cell in DataGridView

Posted on 2006-07-04
3
618 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now