Unable to set focus to a particular cell using the datagridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • svaradan
    New Member
    • Sep 2006
    • 6

    Unable to set focus to a particular cell using the datagridview

    Hi

    I have an issue wherein when the RowLeave event is trigerred ina datagridview, I want to set the focus back to the row where the validation failed. But the cell focus goes to the cell i clicked or tabbed into even though I have set the focus back to the rouge row with a .selected = true property.

    I have tried the following with no success...

    iRowNumber = timesheetdataGr idView.CurrentC ell.RowIndex;
    DataGridViewRow dgvR = timesheetdataGr idView.Rows[iRowNumber];
    dgvR.Selected = true;
    (OR)

    timesheetdataGr idView.Rows[iRowNumber].Selected = true;
    timesheetdataGr idView.CurrentC ell = timesheetdataGr idView[0, iRowNumber];

    Any and all help is appreciated.

    Sonny
  • svaradan
    New Member
    • Sep 2006
    • 6

    #2
    Hi

    It looks to me like since I am clicking out or tabbing onto another row, the mouse down or tab event is interfering with selecting a row. I tried having a command button with the selected.true property set and that works fine. How do I get around this issue.

    Sonny

    Comment

    • karthikeyanv11
      New Member
      • Apr 2007
      • 1

      #3
      Originally posted by svaradan
      Hi

      I have an issue wherein when the RowLeave event is trigerred ina datagridview, I want to set the focus back to the row where the validation failed. But the cell focus goes to the cell i clicked or tabbed into even though I have set the focus back to the rouge row with a .selected = true property.

      I have tried the following with no success...

      iRowNumber = timesheetdataGr idView.CurrentC ell.RowIndex;
      DataGridViewRow dgvR = timesheetdataGr idView.Rows[iRowNumber];
      dgvR.Selected = true;
      (OR)

      timesheetdataGr idView.Rows[iRowNumber].Selected = true;
      timesheetdataGr idView.CurrentC ell = timesheetdataGr idView[0, iRowNumber];

      Any and all help is appreciated.

      Sonny
      Hai,
      I am also facing the same problem.i cant able to place the cursor in a particular cell. Any help?

      Comment

      • mr22
        New Member
        • May 2007
        • 1

        #4
        Originally posted by karthikeyanv11
        Hai,
        I am also facing the same problem.i cant able to place the cursor in a particular cell. Any help?
        Use CellValidating event
        If validation fails, set e.cancel to true

        Comment

        • alagan
          New Member
          • Jul 2007
          • 12

          #5
          Originally posted by svaradan
          Hi

          I have an issue wherein when the RowLeave event is trigerred ina datagridview, I want to set the focus back to the row where the validation failed. But the cell focus goes to the cell i clicked or tabbed into even though I have set the focus back to the rouge row with a .selected = true property.

          I have tried the following with no success...

          iRowNumber = timesheetdataGr idView.CurrentC ell.RowIndex;
          DataGridViewRow dgvR = timesheetdataGr idView.Rows[iRowNumber];
          dgvR.Selected = true;
          (OR)

          timesheetdataGr idView.Rows[iRowNumber].Selected = true;
          timesheetdataGr idView.CurrentC ell = timesheetdataGr idView[0, iRowNumber];

          Any and all help is appreciated.

          Sonny


          No need to do anything simply set the focus to the datagridview1 ....

          Comment

          • hdotnetdev
            New Member
            • May 2007
            • 5

            #6
            Try to use
            dataGridView1.C urrentCell = dataGridView1[columnIndex, RowIndex];

            Comment

            Working...