Board index » cppbuilder » Re: TDBGrid

Re: TDBGrid


2003-09-04 04:01:36 PM
cppbuilder35
"Charlie Page" < XXXX@XXXXX.COM >wrote in message
Quote
I can add a lookup field to a dataset and have a lookup field on the
TDBGrid display a drop down list when the user clicks on it (default
behavior).
What I want is to have the list drop down when the user starts typing
(have the box open without having to have the user use the the mouse to
click). Is there any quick way to do this?
How quick is quick?
This is an adaptation of a scheme that I used to have activated by a MenuItem
with its Shortcut set to F4, that being the standard Windows key for dropping
ComboBoxes in general. The assumption here is that it is not required to
enter text into the edit box and only selections from the list are permitted.
That can be changed if required, also you may not want/need the test for
ButtonStyle as I do here. To achieve proper handling of the Return key I
found it necessary to Post a message and maintain a global flag to prevent
re-entrance. If you also use a KeyUp handler then it may be necessary to test
for "ListDropping" there too.
The keybd_event's emulate the Alt+DownArrow key-strokes that are normally used
to drop the list when the editor is showing, that being the easiest way to get
it to work. As shown it drops the list from Return, Space, F4 or any
character key. Escape works as standard and Return activates the selection
change in the usual way. The only minor defect is that the dropped list does
not handle the function keys so F4 can drop the list but cannot close it, that
could be fixed by adding a message trap. No doubt I'll hear about it if any
bugs show up. Done in BCB4.
.h file
//---------------------------------------------------------------------------
#define CM_DROPPICKLIST (WM_APP + 42)
class TMainForm : public TForm
{
__published: // IDE-managed Components
...
private: // User declarations
bool ListDropping;
void __fastcall CMDropPickList(TMessage &Message);
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(CM_DROPPICKLIST, TMessage, CMDropPickList)
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
cpp file
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
ListDropping = false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MyDBGridKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (ListDropping)
return;
int I = ((TDBGrid*)(Sender))->SelectedIndex;
if (!((TDBGrid*)(Sender))->Columns->Items[I]->ButtonStyle == cbsEllipsis)
{
if ((((TDBGrid*)(Sender))->Columns->Items[I]->PickList->Count>0)
&& ((Key == VK_F4) || (Key == VK_RETURN) || (Key == VK_SPACE))
|| ((Key>= 'A') && (Key <= 'Z')))
{
if (!(IsWindowVisible
(FindWindowEx
(FindWindow(PChar
(((TDBGrid*)(Sender))->Name.c_str()),
NULL), 0, "TPopupListBox",
NULL))))
{
PostMessage(Handle, CM_DROPPICKLIST, 0, 0);
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MyDBGridKeyPress(TObject *Sender, char &Key)
{
int I = ((TDBGrid*)(Sender))->SelectedIndex;
if (!((TDBGrid*)(Sender))->Columns->Items[I]->ButtonStyle == cbsEllipsis)
{
if ((((TDBGrid*)(Sender))->Columns->Items[I]->PickList->Count>0)
&& (Key != 13))
Key = 0;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CMDropPickList(TMessage &Message)
{
ListDropping = true;
try
{
if (ActiveControl->ClassNameIs("TDBGrid"))
{
if (!((TDBGrid*)(ActiveControl))->EditorMode)
((TDBGrid*)(ActiveControl))->EditorMode = true;
keybd_event(VK_MENU, 0, 0, 0);
keybd_event(VK_DOWN, 0, 0, 0);
keybd_event(VK_DOWN, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
}
}
__finally
{
ListDropping = false;
}
}
//---------------------------------------------------------------------------
--
Regards,
Chris Luck.
 
 

Re:Re: TDBGrid

Hi,
Can anyone tell me if it's possible to change the color and font appearance
of a single row in a TDBGrid ?
Tnx
Fret.
 

Re:Re: TDBGrid

Delphi 3, paradox 7
Is it possible to block user from being able to move cursor position from one
record to another and at the same time not to block the grid horizontal scroll
bar ? I tried tdbedit.enabled:=false but that blocks both
 

{smallsort}

Re:Re: TDBGrid

Hello, mruczu?
Quote
Is it possible to block user from being able to move cursor position from
one record to another and at the same time not to block the grid
horizontal scroll bar ? I tried tdbedit.enabled:=false but that blocks
both
Call Abort in the BeforeScroll event of the dataset.
Cheers,
Ignacio
--
Henshin-a-go-go, baby!
 

Re:Re: TDBGrid

I need something like TDBGrid, but to have nice look and feel and to be
freeware/opensource. Is there something like this?
 

Re:Re: TDBGrid

check out www.scalabium.com (free)
"Oliver Young" <none>wrote in message
Quote

I need something like TDBGrid, but to have nice look and feel and to
be
freeware/opensource. Is there something like this?


 

Re:Re: TDBGrid

Direct link is www.scalabium.com/smdbgrid.htm
:-)
"Andy" < XXXX@XXXXX.COM >сообщи?сообщила ?новостях следующе?
Quote
check out www.scalabium.com (free)

"Oliver Young" <none>wrote in message
news:3fd97a46$ XXXX@XXXXX.COM ...
>
>I need something like TDBGrid, but to have nice look and feel and to
be
>freeware/opensource. Is there something like this?
>
>


 

Re:Re: TDBGrid

What event should I use to detect the user
changing rows, whether by mouse or arrow
or programmatically?
I was using OnScroll, but that also fires even
if they just scroll the scroll bar and don't change
the selected row.
That actually sounds correct and makes me
think that I am using the wrong event.
Suggestions?
--
Thanks,
Brad White
 

Re:Re: TDBGrid

Brad White wrote:
Quote
I was using OnScroll, but that also fires even
if they just scroll the scroll bar and don't change
the selected row.
Scrolling the TDBGrid changes the selected row.
--
Cheers,
Ignacio
Help improve Delphi: qc.borland.com/
 

Re:Re: TDBGrid

Hello Brad,
I believe TDataSet.AfterScroll will help you.
"Brad White" <bwhite at inebraska.com>wrote in message
Quote
What event should I use to detect the user
changing rows, whether by mouse or arrow
or programmatically?
I was using OnScroll, but that also fires even
if they just scroll the scroll bar and don't change
the selected row.
That actually sounds correct and makes me
think that I am using the wrong event.

Suggestions?

--
Thanks,
Brad White


 

Re:Re: TDBGrid

"Ignacio Vazquez" <ivazquezATorioncommunications.com>wrote in message
Quote
Brad White wrote:

>I was using OnScroll, but that also fires even
>if they just scroll the scroll bar and don't change
>the selected row.

Scrolling the TDBGrid changes the selected row.

Yes. This contributes to the problem.
Also, turns out there is no OnScroll. We are using
AfterScroll. Sorry for being imprecise.
When the user changes records, we update a number
of other objects and components on the form to stay
in sync.
This works fine until they want to grab the scroll bar
and scroll to the bottom of the grid.
It appears to be getting AfterScroll for *every*
intermediate row. This slows things down considerably.
Is there a way to short-circuit this.
If I could see that I've got AfterScroll events pending,
I could just skip the rest of the current sync. But I don't
know how to see that.
--
Thanks,
Brad White
 

Re:Re: TDBGrid

Has anyone a short example, that can be posted, on how to use TDBGrid?
Blue Knight
 

Re:Re: TDBGrid

How can I set font color (red, blue, green...) for every rows?
Thank you.
 

Re:Re: TDBGrid

Is it possible to get a small arow to point
the sorting order in a column title of a TDBGrid ?
 

Re:Re: TDBGrid

I have a TDBGrid that has some columns with numbers. I have it set up
so that when you press the space bar, it toggles the number from 0 to 1
or 1 to 0. This works OK. But I would like for it to then step to the
next column. Here if the code I have:
void __fastcall TBrochureForm::DBGrid1KeyPress(TObject *Sender, char &Key)
{
if(Key == VK_SPACE)
{
Toggle(); // Toggles the number - works OK
Key = 0;
if(DBGrid1->SelectedField == CustEditDM->CustListCURCAMP)
DBGrid1->SelectedField == CustEditDM->CustListCURCONT;
}
}
This does not step to the next field. I also tried:
if(Key == VK_SPACE)
{
Toggle();
DBGrid1KeyPress(this, VK_TAB);
}
This did not work either. Any ideas?