Board index » cppbuilder » Help!! DBGrid Example wanted

Help!! DBGrid Example wanted


2003-10-10 11:13:02 PM
cppbuilder31
Hi All,
Does anyone have some sample code I could have a look at, I
want to have a dbgird component on a form, I want to be able to double
clck on a cell this would then open up another form which would show
all the information in that row of the database.
Hope this make sense to you, thanks in advance.
regards
Adrian
BTW, currently using CBuilder 4 Pro
 
 

Re:Help!! DBGrid Example wanted

"Adrian Stokes" < XXXX@XXXXX.COM >wrote in message
Quote
I want to have a dbgird component on a form, I want to be
able to double clck on a cell this would then open up another
form which would show all the information in that row of
the database.
TDBGrid has an OnDblClick event (property). Implement an eventhandler in where
you create a form which can deal with editing the selected record.
The manner in which a record is edited, is really up to you to decide. You
could create a specific form for each record (dataset). Or, if you want to edit
a datasets record in generic manner, you'll have to iterate through all the
fields and dynamically create appropriate edit controls and bind them to the
corresponding fields. Or leave the editing of the record to the grid itself.
The grid will already create the appropriate editors for you depending on the
actual field.
Ralph
 

Re:Help!! DBGrid Example wanted

Hi,
Thanks for the reply, but I think you have misunderstood the point of
the post. I wanted to have a look at some sample code, so I could
then see which woul;d be the best way for me to tackle what I want to
do. I have seen what I want to achieve done in delphi, but have found
know example in cbuilder.
regards
Adrian
On Fri, 10 Oct 2003 17:54:58 +0200, "Ralph Kazemier"
< XXXX@XXXXX.COM >wrote:
Quote

"Adrian Stokes" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I want to have a dbgird component on a form, I want to be
>able to double clck on a cell this would then open up another
>form which would show all the information in that row of
>the database.

TDBGrid has an OnDblClick event (property). Implement an eventhandler in where
you create a form which can deal with editing the selected record.

The manner in which a record is edited, is really up to you to decide. You
could create a specific form for each record (dataset). Or, if you want to edit
a datasets record in generic manner, you'll have to iterate through all the
fields and dynamically create appropriate edit controls and bind them to the
corresponding fields. Or leave the editing of the record to the grid itself.
The grid will already create the appropriate editors for you depending on the
actual field.


Ralph


 

{smallsort}

Re:Help!! DBGrid Example wanted

"Adrian Stokes" < XXXX@XXXXX.COM >wrote in message
Quote
Thanks for the reply, but I think you have misunderstood the point of
the post. I wanted to have a look at some sample code, so I could
then see which woul;d be the best way for me to tackle what I want to
do. I have seen what I want to achieve done in delphi, but have found
know example in cbuilder.
I'm not sure what kind of sample code you are expecting, but here goes.
Following code creates a form and shows all field values in a
TMemo-component;
#include <memory>
void __fastcall TForm1::DBGrid1DblClick(TObject* Sender) {
if(DBGrid1->DataSource && DBGrid1->DataSource->DataSet) {
std::auto_ptr<TForm>Form(new TForm(NULL));
TMemo* Memo = new TMemo(Form);
Memo->Parent = Form;
Memo->Align = alClient;
TDataSet = DBGrid1->DataSource->DataSet
for(int i = 0; i < DataSet->Fields->Fields->Count; i++) {
AnsiString S;
TField* Field = DataSet->Fields->Fields[i];
S.sprintf("%s = %s",
Field->FieldName.c_str(),Field->AsString.c_str()
);
Memo->Strings->Add(S);
}
Form->ShowModal();
}
}
If is not what you are looking for, please rephrase your question.
Ralph