DataGridView + Focus to a Row Cell

I have to check the validation of DataGridView and have to check the value should not repeate more then one time. I Solve this problem just by adding the following two lines of code and its working very fine. Do you facing the same problem, Please go through and it will definetely resolve your problem.

If you know the cell, like having a reference to it from the variable desiredCell you can simply do the following:

dataGridView1.CurrentCell = desiredCell;

Solve na?? Now add your comments buddy. 🙂
Vijay Modi


About Vijay Modi

Having 12+ years of experience in web application development. Expertise in various domains like E-Commerce, E-Learning, Insurance. I have expertise in web application development, window application development, Performance improvement, bug fixing etc. I have worked on various Microsoft technologies including ASP.Net, MVC, WebApi, WCF, Entity Framework, WPF, Window Application Development, AWS, Azure, AngularJS 2.0 / 1.5.2, .NetCore framework, jQuery. I am believing in quality work and achieving deadlines. Also like to work on new technologies and quick learner.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

11 Responses to DataGridView + Focus to a Row Cell

  1. amit says:

    not working when i want focus to the previuos cell

  2. Sunil KUmar Deeti says:

    hi vijay,
    please tell me how to play videos in webpage………
    here im using datalist………..
    play videos in that like orkut videos………..
    please help me………..

  3. thank you very much

  4. John says:

    Vijay – I would value your ideas about this aspect of the DataGridView.

    It is generally easy to set the focus to a cell and there are several ways to do it. However, the problem I’m having is that the DataGridView is being populated during the Form Load event, and then when it is displayed the focus is on the last cell that was populated; but I want the focus to be at the top left cell of the control (i.e. row 0, col 0). When I try the various methods, I get an exception saying that you can’t select an invisible cell. I’ve even put code in the VisibleChanged event for the DataGridView, checked that it is visible, and then tried to set the focus to the top left cell: I still get the message that you can’t do this to an invisible cell.

    How do I set the DataGridView to be focused on the top left cell after it is done being populated when this populating is happening before the DataGridView is displayed?


  5. dev says:

    you have solve this problem but my problem with cellvalidated in particular cell valid in the range.

  6. Kamal says:

    Hi John, For this once you have populated the DataGridView then use
    dataGridView1.Row[0].Selected = true;
    dataGridView1.CurrentCell = dataGridView1.Row[0].Cells[0];

  7. bhupendra Singh says:

    No Boss Its not done

  8. rajesh says:

    Good Answer.
    need brain to use it according to desired result.

  9. Thep says:

    Thank you very much

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s