Mega Search
23.2 Million


Sign Up

Make a donation  
How to navigate programmatically in DBGrid  
News Group: borland.public.delphi.ide.general

Okay, all you altruistic over-achievers, here's my next thing. I have a form containing a number of edit boxes, each of which triggers a database search (on pressing the [Enter] key), based on an SQL string that is formed from the contents of the active edit box (and the underlying field it represents). The results of such a search go into a TDBGrid (via a TDataSource). The user then selects the record he was looking for (in the DBGrid) and clicks a button, and things move on.

Everything works fine, except for one possible scenario. If the user enters a numeric string in the CustomerNo box and presses [Enter], the form must run a search, because it cannot know whether the entered data constitutes a complete customer number (which the user must have known in advance) or a search pattern (in which the user is looking for a customer number that starts with the entered numeric string). 

So, to avoid pi##ing the user off too much, if the entered data was in fact a complete customer number (e.g. '1234') and the search returned >1 rows (e.g. for customer numbers '1234', '12340', '12341', etc.), I want the program to automatically select the row in the DBGrid that matches CustomerNo exactly. (If no match, just stay on 1st row). Then, the user will only need to execute one more click to confirm the that the selected record represents the desired data.

My problem is that I can't figure out how to navigate the bloody DBGrid in code. It seems that you can't move using methods like Next or Prev in a TDBGrid, which would have been nice. I've looked at using a TClientDataSet, but I couldn't see where that would get me. I'm now poking around in the TCustomDBGrid class (and the TBookmarkListclass), but it's getting a bit scary. (I've only been coding in Delphi for 3 months, so I'm still pretty green.)

Any advice will bemuch appreciated. I'm probably being stupid about this, so please feel free to smack me about, a bit.



Vote for best question.
Score: 0  # Vote:  0
Date Posted: 11-Jan-2008, at 3:26 AM EST
From: Allen Nugent