Munish Goyal
Munish Goyal

Reputation: 1409

How to prevent a gridview to get focus?

I have 2 grids. When user is doing edits in one grid, I want to disable the other grid from getting focus, or atleast other grid from changing its foccussed row.

Example: Parent grid, children grid.

If user is making edit in children of particular parent. I want to prevent user from suddenly shifting focus to different parent row. how to do that ?

Upvotes: 0

Views: 2194

Answers (2)

Azhar Khorasany
Azhar Khorasany

Reputation: 2709

There are a lot of ways to do this but thats how I would do it (just a concept so ignore if any property does not match):

Create a property called mode and then use enumeration to set it to Edit or None etc.

Suppose you have GridViewParent and GridViewChild. In the FocusedRow event of child grid, at the start of all code, set the value of mode to Edit and at the end of all code in the event set it to None.

Then in the FocusedRow event of parent grid check whether the mode value is edit or not, if it is edit then use e.Cancel or something to get out of the focused event of the parent.

Now if you let me know exactly which grid are you using I might send you the code.

Upvotes: 0

Dave Alger
Dave Alger

Reputation: 359

The only ways you can prevent a control receiving focus is to change it's Enabled or Visible properties.

Simply changing the parent's Enabled property to "false" (e.g. for the CellBeginEdit) and then back to "true" (e.g. in the CellEndEdit event) will prevent the user from selecting a new parent row.

Upvotes: 1

Related Questions