Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtGridWnd and EditCell Collapse All
Subject Author Date
Suhai Gyorgy Sep 21, 2007 - 6:55 AM

Dear Support,

Your Help file says that CExtGridBaseWnd::EditCell method "activates the in-place editor control for a specified cell and returns...". But used this method returns only after the user finished editing in the cell. And even though Help file states that bContinueMsgLoop parameter is used for different purposes, I tried setting it to false but that didn’t change this behaviour either. I would like to
I can hack it by sending WM_LBUTTONDOWN message to the grid, but I really don’t like this solution ( maybe its matching WM_LBUTTONUP should be sent as well ).

Is there any other solution for this? Actually I need it for the following situation:

In OnGbwFocusChanging I check if the user is trying to leave the selected (focused) line (fullrow selection is set). Then I check if the "key" cell of the line is filled, otherwise I warn the user and force the key cell to get into edit mode. If I use EditCell here and the user tries to change the selection by clicking on another line (thus trying to change the focus as well), the key cell gets into edit mode and after completing the edit, the selection goes onto the line clicked earlier (focus stays on the line we just edited). If I could somehow refuse changing the selection in OnGbwFocusChanging, the problem could be solved without the use of PostMessage.

Thank you!

Technical Support Sep 27, 2007 - 2:13 PM

We received your e-mail and replied yesterday.

Suhai Gyorgy Sep 28, 2007 - 2:46 AM

The solution is working great. Thank you very much for the help!

Technical Support Sep 24, 2007 - 12:40 PM

We have just created the simplest possible application which should meet your requirements. Everything is implemented in the CMyGridWnd class except for test data initialization. Please let us know if it is what you are looking for?

Suhai Gyorgy Sep 26, 2007 - 6:44 AM

I’ve replied by e-mail, along with the modified project.

Technical Support Sep 23, 2007 - 2:02 PM

We need to discuss some more details. When the user is typing something in a cell and wants to finish editing, the user can do this in several ways. When the user presses Enter or Tab, VK_RETURN or VK_TAB can be handled to check the input. But what about when the user clicks or double clicks any cell in the same row? Should we treat this as the user finishes editing and some handler is needed to verify the input?

Besides what should we do if other application or popup window is activated? Should we remove the edited row at all in this case?

We think in any case all grid cells in the grid should be marked as read-only and only one row should be editable until you add it to the database. This makes the entire task simpler because you will be unable to start editing other rows. But it is still not clear when the grid control will know that the data input is complete in all the cells in the editable row and data base writing should be performed.

It is also possible to simplify your task. We can enable any input in any cell inside the edited row. You will be able to activate the editor for any cell and use any keys except for VK_RETURN. The VK_RETURN key will be used for final data verification in all the cells and further writing to database or starting the editor in the first found column with incorrect data.

Suhai Gyorgy Sep 24, 2007 - 2:11 AM

Here are the answers to your questions one by one:

> We need to discuss some more details. When the user is typing something in a cell and wants to finish editing, the user can do this in several
> ways. When the user presses Enter or Tab, VK_RETURN or VK_TAB can be handled to check the input. But what about when the user clicks
> or double clicks any cell in the same row? Should we treat this as the user finishes editing and some handler is needed to verify the input?
No, verifying is not needed in this case.

> Besides what should we do if other application or popup window is activated? Should we remove the edited row at all in this case?
No, verifying and removing the editing row is not needed in this case either.

> We think in any case all grid cells in the grid should be marked as read-only and only one row should be editable until you add it to the database.
This is already implemented in our application.
> This makes the entire task simpler because you will be unable to start editing other rows. But it is still not clear when the grid control will know
> that the data input is complete in all the cells in the editable row and data base writing should be performed.

I couldn’t provide the exact code earlier, but here is the condition inside my OnGbwFocusChanging to tell me when to do verification (and if verification is passed, I do database writing: if ( ptOldFocus.y >= 0 && ptOldFocus.y != ptNewFocus.y && row with index ptOldFocus.y is editable). Inside this if I do the verification and return false; if it fails and write to database (and change cells to read-only) otherwise. All I need is to be able to reset selection changing along with focus changing when I need to return false. Please, reread all the posts of this thread to check the solution I already have with PostMessage. I’m just looking for a function which would force editing mode and returns right away.

> It is also possible to simplify your task. We can enable any input in any cell inside the edited row. You will be able to activate the editor for any
> cell and use any keys except for VK_RETURN. The VK_RETURN key will be used for final data verification in all the cells and further writing to
> database or starting the editor in the first found column with incorrect data.
No, this special use of the VK_RETURN would make the grid and this feature very user-unfriendly, because it is not what the user expects from a grid.

Technical Support Sep 22, 2007 - 12:50 PM

It seems you should use a different approach for controlling user input and preventing input of incorrect data. You can override the CExtGridWnd::OnGridCellInplaceControlTextInputComplete() virtual method which is invoked after inplace editor is destroyed. This method allows you to apply or cancel the editing result. You can start the editor again if the result is invalid. You can override the CExtGridWnd::OnGridCellInplaceControlTextInputVerify() virtual method for implementing on-the-fly verification during text typing. You can override the CExtGridWnd::OnGridCellInplaceControlPreTranslateMessage() virtual method and implement message pre-translation for the inplace active editor window. You can override the CExtGridWnd::OnGridCellInplaceControlWindowProc() virtual method and hook the window procedure of the inplace active cell editor for handling mouse and keyboard events like you need. You can let us know what exactly you are going to edit and how exactly it can be verified so we can code a small grid with complete prevention of incorrect input.

Suhai Gyorgy Sep 22, 2007 - 3:05 PM

We need to verify input when user tries to leave the selected row. The grid in question is really a read-only grid, but when user presses a button on the dialog, a new line is added to the grid, which stays editable only while the user stays on the row. The item represented by the row should be inserted to the database after all needed fields are filled and the user leaves the row. But the solutions you suggested are all for verifying input during or instantly after editing one single cell.

Technical Support Sep 21, 2007 - 11:07 AM

The local message loop is tracked until cell editing is complete. But the grid supports a feature which allows you to edit the next/previous grid cell when the user presses the right/left arrow keys in the end/beginning of the active cell editor window. That is why we implemented a re-usable message loop. The user can potentially walk through one million of cells and grid should not invoke the cell editing message loop for each cell again because the stack size is not unlimited. You should not expect any results from the EditCell() API. It can wait for the message loop and end of editing in certain case and do not wait in other cases. We believe we have implemented all the possible virtual methods for controlling start/end/validation and on-the-fly validation events in the in-place activated cell editor controls. Please let us know more details about your task so we can help you. Especially which events you need to catch?

Suhai Gyorgy Sep 21, 2007 - 3:01 PM

I want to validate one cell of a line when the user leaves the line (selects another line, either with up/down arrow or by clicking on another line). If validation fails, I want to warn the user with a messagebox and force the inproper cell into edit mode.

Unfortunately my code is not in front of me right now, but here is a simplified version of it.

	virtual bool OnGbwFocusChanging(
		const POINT & ptOldFocus,
		const POINT & ptNewFocus,
		bool & bEnsureVisibleColumn,
		bool & bEnsureVisibleRow,
		bool & bResetSelectionToFocus,
		bool & bRedraw
		)
	{
		if ( !CExtGridWnd::OnGbwFocusChanging( 
			ptOldFocus,
			ptNewFocus,
			bEnsureVisibleColumn,
			bEnsureVisibleRow,
			bResetSelectionToFocus,
			bRedraw) )
			return false;
		if ( ptOldFocus.y >= 0 && ptOldFocus.y != ptNewFocus.y ) { // focus is changing from a valid line to another one
			if ( key cell of ptOldFocus.y line is invalid ) {
				AfxMessageBox(_T("You made a mistake"));
				EditCell(key column index, ptOldFocus.y);
				return false;
			}
		}
		return true;
	}
Using this code, when the user makes a mistake in the key cell and then clicks another line, the message box pops up, then the key cell gets into edit mode and when the user finishes editing, the previously clicked line gets the selected state but the focus stays on the line we just edited. I want the selection state to stay on the edited line as well. I hope it’s clear.