I have three DBGrids and three Tables, and two of them are linked with Master Fields and work as expected. When the user clicks on grid-1, it shows three items in grid-2.
When the user clicks on grid-2, I want to use Locate to select the Row in grid-3
Problem is that the grid-2 OnCellClick event is fired before the data has changed to the appropriate Row. e.g.
Grid-2
Flowers <-- this has focus and Dirt has focus in grid-3
Weeds
Trees <-- then I click here
Grid-3
Dirt
Water
Gum <-- and using Locate in the grid-2 OnCellClick I
want it to show Gum but grid two is still
internally on Flowers and stays on Dirt
It seems that the grid does not change to the Row until after the OnCellClick event.
I need an AfterCellClick event.
Can someone please shed some light on how to go about that?
Thanks
You shouldn't be using OnCellClick. Use the TDataSet.OnAfterScroll instead. It's called automatically when the record (row) pointer is moved, after the movement is done. This means that when the grid attached to the second table is clicked and the record pointer is moved from Flowers to Trees, the second table's OnAfterScroll event will be fired after the row changes, and in that event handler you can do the appropriate Locate in the third table.
Related
I'd like to run a procedure--once--whenever the selected item in a ListView changes. The obvious choice would be OnSelectItem, but it's called twice when the user moves from one selected item to another (using mouse or arrow keys). Similarly, OnChange is called three times when moving between items.
Is there an event generated only once under these conditions? OnClick is generated once, but doesn't cover moving between items using arrow keys, etc.
You can do it like this using OnSelectItem.
Remember the last selected item.
When the OnSelectItem fires, check if the current selected item differs from the one you remembered.
If so, perform your task, and make a note of the new selected item.
I have a TDbGrid linked to a dataset with rows displayed in this grid.
When scrolling on the grid, it moves the selected row of the dataset, which means that if I want to go at the bottom of the grid, it browse every record and the record behind the grid only appears when I am at the bottom of the grid,
The behavior I except is : I want the screen to move but not my record selected ( so the only way to change row would be to click on the row).
Have you got any idea on how to do that?
The behaviour that I except is the same as in the 'Object inspector' of the IDE delphi 10.
This is not possible, the TDBGrid is designed such that it only holds the viewable records in its data buffer. So the selected record must be one in the viewable range. This is to minimize data exchange traffic between the server and the client.
I seem to have a mental block with this one.
I need to save recent changes to a Record. I am doing it OK with buttons for "New" "Edit" "Post" "Next" etc but when a user double-clicks a DBGrid, it is now too late to make changes as the DBGrid selection has moved the database cursor to the selected record.
I can't use AutoUpdate as the data that may have been changed is not something the user would have directly entered, it is a value that is changing all the time.
I'll try to describe it better: While the user is reading a Test-page, a timer is counting down or up. When they click the "Next" or "Prior" buttons I can save the timer setting. But, if they Double-Click the DBGrid I have no way of first changing the current Record before the selection moves to the clicked-Record.
I tried using the
Procedure TForm1.tblTestOnBeforeScroll(...
begin
tblTest.Edit;
tblTest.FieldByName('TimerCt').AsInteger:=ClockCtr;
tblTest.Post;
end;
But, that crashed the database, not surprisingly, but I thought I would give it a try before asking here.
How do I deal with the current record? I do not want to disallow the double-click if possible as it seems nice and intuitive for the user.
I'm afraid that what you do on DBGrid is a wrong in concept action.
Key point is DBGrid is a data aware control. So everything you do on it must based on it's datasource then it's dataset.
There is a DblClick event on TDBgrid. But still you have to check it's dataset to see what record is active.
The code you shown above clearly lead you to an endless loop.
When you doing a scroll, the dbgrid will call OnBeforeScroll event, moving the active record
and call OnAfterScroll. Your OnBeforeScroll code does an data update. Then dbgrid abort its operation cause of data change. Then after data update, it try to scroll again, and the data change happen again. Endless loop happen here.
best regard
Apologies in advance if I'm misunderstanding you, but it seems to me that either the premise of your question is wrong or there is something relevant you haven't told us about what you're doing. Please try the following:
If you don't have one already, please temporarily add a DBNavigator to your form and connect it to the same DataSource as your DBGrid. The point of doing this is so that you can more clearly see what's going on.
Then, in your DBGrid's Options, set dgEditing to True.
Finally, comment out or disable your BeforeScroll handler, save and run your program.
Now, click once in some cell in your DBGrid that contains a value which it's ok to change. Click it a second time so that it selects the value in the cell rather than the cell per se.
Make some change to the cell value, but do nothing else for the time being. You should notice that a) the current record indicator of the DBGrid has changed from a black triangle to an I-Beam graphic, like ][ and b) that the tick and cross buttons of the DBNavigator are now enabled.
Now, without doing anything else on the form, click in another row of the DBGrid. You should find that a) the change to what was the current record in step 5 has been saved and b) the current row indicator reverts to the black triangle and the DBNav's tick and cross buttons are disabled.
(If you don't get the behaviour I've just described, create a minimal new project and try that instead, as some other change you've made in your existing project may be interfering with it).
What I've described in 5 & 6 is the default behaviour of a DBGrid and insofar as I understand your q, that seems to be the behaviour you're trying to achieve. If that's not the behaviour you want, please explain exactly how what you do want differs. It's not clear to me where the user double-clicking on the grid comes into your q, except that that action may move the dataset's cursor (if the dbl-click is on a different row than the current one), but as the default DBGrid behaviour will save changes to the current row before it moves the dataset's cursor, it will do what you seem to want automatically.
Btw, what "AutoUpdate" do you mean? Did you mean TDataSource's AutoEdit property?
I have a TcxGrid which consists of a master TcxGridLevel and 2 child TcxGridLevels (all of which use a TcxGridDBTableView). I would like to hide one of the child levels depending on the value of the master level record values. How do I go about this?
Here is a link to DevExpress describing what you want:
https://www.devexpress.com/Support/Center/Question/Details/Q96738
But this has some disadvantages in my opinion. First it is quite slow with bigger datasets. Second it comes to "flicker" when your master level changes frequently and the grid has to be redrawn. Maybe it is possible to set a filter to your detail-dataset so the details are "empty" when your nmaster has the correct condition. There is a property in TcxGrid to hide empty detail-tabs automatically.
Somewhat out of context but in case the link goes dead again:
1) How can I trigger Level3 OnGetGridView, because Level3 View was not change as I was expected
The OnGetGridView event is raised only once when the detail is first expanded. After the event handler has been executed, the specified GridView’s clone is created and cached so that the event doesn't fire when expanding the same master record next times. If you need the event to be raised later, you can clear all detail clones by calling the master DataController’s ClearDetails method or ClearDetailLinkObject methods.
You can find this information in the "TcxGridLevel.OnGetGridView" topic of the ExpressQuantumGrid's documentation.
2) I am also changing Level2 and Level3 Caption for every Gridview that it showing, but the changing is not automatically, sometime the Detail View need to be close and open again to make the Caption change.
If we're not mistaken, you change the Level's Caption in its OnGetGridView event handler. If so, the new caption isn't applied immediately because painting of the corresponding element isn't completed. As a workaround, you can perform a "delayed" operation by posting a custom message. I've attached a sample project to illustrate this approach in action. Hopefully, it will serve your needs, and adapting it won't be aproblem.
When you select multiple nodes of a JvTreeView, and then try to drag these nodes, the JvTreeView selects the node you clicked to drag, rather than initiating dragging all the selected nodes. You end up dragging only this single node.
Is it possible to drag multiple nodes in a JvTreeView? I am using Delphi 2007.
UPDATE: Oddly enough, if I hold down CTRL+SHIFT when dragging the items, I can successfully drag them all. Any ideas?
Suppose MultiSelectStyle is the default [msControlSelect], then the answer to your question is 'you don't release the control key when you're selecting the last item and beginning dragging'.
The culprit is in TJvTreeView.WMLButtonDown in JvComCtrls.pas. Code there tests if 'Ctrl' is pressed when the TreeView is MultiSelect, and clears all items and selects the clicked item if 'Ctrl' is not pressed. It should instead test if the clicked item is already selected and do nothing if it is.
You can see the broken behavior without dragging. Multi select a few items and then click a selected item with the mouse. The VCL TreeView do not select or de-select anything, while the JVTreeView, instead, de-selects all items and selects the clicked one.
Yes absolutely, I do it all the time.
Of course Multi-Select needs to be True and you may need to have a look at the TTreeView's MultiSelectStyle. That controls what type of nodes can be selected at the same time. For example if msSiblingOnly is set to true, you can only select sibblings.
Are you using dmAutomatic or dmManual. If the latter, it could be that you are doing something in the OnMouse* events that is negating the multi-selection you made earlier.