Board index » cppbuilder » DBGrid

DBGrid


2003-07-02 09:39:35 AM
cppbuilder76
I am using a DBGrid.
I have a event function that is called when the user clicks on a cell.
it sends the column that is clicked.
so Column->Field->Text will give you the data for that cell.
My problem is, I want to use this function and access everything
on the roll. Like using the Column->Index to get each entry on that row.
Anyone have any ideas?
I might be going about this the wrong way.
I am trying to show the user all the data in a table and when they click on one cell, i want to show them the whole row of data in a dialog with questions.
any suggestion is welcome.
thanks in advance.
-Student who's stuck thinking inside of the box. LOL --
 
 

Re:DBGrid

Does it have a "On Custom Draw Cell" event on one of the fields? Because if
it does you could find out the selected and grab the data this way (note
dxMemData is my dataset and edNum is an edit box (TEdit)):
if (ASelected & !edNum->Focused () ) {
edNum->Text = AText;
if ( dxMemData->FindField( "number" )->AsString == edNum->Text )
//just an error checking mechanism{
edStatus->Text = dxMemData->FindField( "status" )->AsString;
//grabbing the info from the dataset
edSubject->Text = dxMemData->FindField( "subject" )->AsString;
edRecipient->Text = dxMemData->FindField( "name" )->AsString;
edID->Text = dxMemData->FindField( "id" )->AsString;
}
}
Hopefully this helps in some way
"bishop" < XXXX@XXXXX.COM >wrote in message
Quote

I am using a DBGrid.
I have a event function that is called when the user clicks on a cell.

it sends the column that is clicked.
so Column->Field->Text will give you the data for that cell.

My problem is, I want to use this function and access everything
on the roll. Like using the Column->Index to get each entry on that row.

Anyone have any ideas?
I might be going about this the wrong way.

I am trying to show the user all the data in a table and when they click
on one cell, i want to show them the whole row of data in a dialog with
questions.
Quote

any suggestion is welcome.

thanks in advance.

-Student who's stuck thinking inside of the box. LOL --
 

Re:DBGrid

A quick "cheat" would be
OnMouseUp ...
YourDBGrid.Columns[YourColumn].Width := TheWidthYouWant;
"David Dvali" < XXXX@XXXXX.COM >wrote in message news: XXXX@XXXXX.COM ...
Quote
How can I disable resizing of only one column in DBGrid?


 

{smallsort}

Re:DBGrid

"Alberto Vieira de S?Biason" < XXXX@XXXXX.COM >wrote:
Quote
how do I do to place a checkbox in a column of the dbgrid?
You need to draw the cells yourself and devise a method for
keeping track of it's state and detecting when when it's
clicked.
If you search the archives, you might find a sample for a
DBGrid. The following is for a StringGrid where all columns
have a checkbox. I included LoadAnimalGrid so that you can see
how the Checked and CanCheck is initialized for each cell:
//-------------------------------------------------------------
void __fastcall TForm1::LoadAnimalGrid()
{
TStringList* pTemp = Lists->Tmp;
bool Checked = false, CanCheck = true;
String Path = DataPath;
Path += DataFileNames[ Animals ];
pTemp->LoadFromFile( Path );
for(int x = 0; x < pTemp->Count; x++)
{
int Col = x % amlGrid->ColCount, Row = x / amlGrid->ColCount;
amlGrid->Cells [ Col ][ Row ] = pTemp->Strings[ x ];
amlGrid->Objects[ Col ][ Row ] = reinterpret_cast<TObject*>( MAKELONG( Checked, CanCheck ) );
}
CanCheck = false;
int LastCol = (pTemp->Count - 1) % amlGrid->ColCount;
if( LastCol < amlGrid->ColCount - 1 )
{
int Row = (pTemp->Count - 1) / amlGrid->ColCount;
for( int Col = LastCol + 1; Col < amlGrid->ColCount; ++Col )
{
amlGrid->Cells [ Col ][ Row ] = "Undefined Animal";
amlGrid->Objects[ Col ][ Row ] = reinterpret_cast<TObject*>( MAKELONG( Checked, CanCheck ) );
}
}
for( int Row = ((pTemp->Count - 1) / amlGrid->ColCount) + 1; Row < amlGrid->RowCount; Row++)
{
for( int Col = 0; Col < amlGrid->ColCount; Col++)
{
amlGrid->Cells [ Col ][ Row ] = "";
amlGrid->Objects[ Col ][ Row ] = reinterpret_cast<TObject*>( MAKELONG( Checked, CanCheck ) );
}
}
}
//-------------------------------------------------------------
void __fastcall TForm1::amlGridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State)
{
TStringGrid *pGrid = amlGrid;
String pText = pGrid->Cells[ ACol ][ ARow ];
TCanvas *pCanvas = pGrid->Canvas;
pCanvas->Font->Color = pGrid->Font->Color;
if( !pText.IsEmpty() )
{
if( !HIWORD( reinterpret_cast<int>( pGrid->Objects[ ACol ][ ARow ] ) ) ) pCanvas->Font->Color = clGrayText;
pCanvas->FillRect( Rect );
if( ACol == pGrid->Col && ARow == pGrid->Row ) DrawFocusRect( pCanvas->Handle, &Rect );
TRect R = Rect;
OffsetRect( R, 2, 1 );
R.right = R.left + GetSystemMetrics( SM_CXMENUCHECK );
R.bottom = R.top + GetSystemMetrics( SM_CYMENUCHECK );
unsigned int BoxState = DFCS_BUTTONCHECK;
if( LOWORD( reinterpret_cast<int>( pGrid->Objects[ ACol ][ ARow ] ) ) ) BoxState |= DFCS_CHECKED;
DrawFrameControl( pCanvas->Handle, &R, DFC_BUTTON, BoxState );
Rect.left += R.right - R.left + 3;
}
else pCanvas->FillRect( Rect );
DrawText( pCanvas->Handle, pText.c_str(), -1, &Rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER );
}
//-------------------------------------------------------------
void __fastcall TForm1::amlGridSelectCell(TObject *Sender, int ACol, int ARow, bool &CanSelect)
{
CanSelect = HIWORD( reinterpret_cast<int>( amlGrid->Objects[ ACol ][ ARow ] ) );
}
//-------------------------------------------------------------
void __fastcall TForm1::amlGridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
int Col, Row;
amlGrid->MouseToCell( X, Y, Col, Row );
amlClickPoint = Point( Col, Row );
}
//-------------------------------------------------------------
void __fastcall TForm1::amlGridMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
int ACol, ARow, Col = amlClickPoint.x, Row = amlClickPoint.y;
amlGrid->MouseToCell( X, Y, ACol, ARow );
if( ACol == Col && ARow == Row )
{
bool CanCheck = HIWORD( reinterpret_cast<int>( amlGrid->Objects[ Col ][ Row ] ) );
if( CanCheck )
{
bool Checked = !LOWORD( reinterpret_cast<int>( amlGrid->Objects[ Col ][ Row ] ) );
amlGrid->Objects[ Col ][ Row ] = reinterpret_cast<TObject*>( MAKELONG( Checked, CanCheck ) );
RECT R = amlGrid->CellRect( Col, Row );
InvalidateRect( amlGrid->Handle, &R, false );
}
}
}
//-------------------------------------------------------------
~ JD
 

Re:DBGrid

how do I do to place a checkbox in a column of the dbgrid?
 

Re:DBGrid

Hi all,
I'm working in a DBGrid and when I push Tab key the cursor goto the
next row of the DBGrid
and automatic do an Insert but I only want to go to the next column . What
is the problem ?
Thank you.
 

Re:DBGrid

How can I Get new entered text from DBGrig , by using
none of this :
Moving to another column or row
changing controls focus .
FOR EX : Func GetTextBuf works only in TEdit's and Combos
but not in Grids
 

Re:DBGrid

Trabalho com oracle 9i e tenho que fazer um trabalho em delphi 7.
Ao criar uma rotina de manutenção em uma de minhas tabelas através do
DbGrid, obtenho um pequeno problema com campos float ou numeric(12,2). Este
ao ser exibido no grid, não possiona as casas decimais.
Ex: valor - 1.54 ou 1,540.10 - o grid retorna 154 ou 14501
No sqlClienteDataSet foi criado os fields:
VALOR DataType ftFMTBcd precision 32 e size 8
Li em um de meus livros que poderia fazer da sequinte forma
(sqlclientDataSet1.FieldByName('Valor') as
tFloatField).DisplayFormat:='###,###,###';
Porem o seguinte erro ?apresentado
Invalid Class typecast
Caso voc?possa me ajudar, fico muto agradecida.
Monica
 

Re:DBGrid

Qu?Delphi estás usando?
Debes usar mejor el formato
#,##0.00
Disculpa el mensaje en español, pero no hablo portugues...
"Fernando(Brasil)" < XXXX@XXXXX.COM >escribi?en el mensaje
Quote
Trabalho com oracle 9i e tenho que fazer um trabalho em delphi 7.

Ao criar uma rotina de manutenção em uma de minhas tabelas através do
DbGrid, obtenho um pequeno problema com campos float ou numeric(12,2).
Este
ao ser exibido no grid, não possiona as casas decimais.

Ex: valor - 1.54 ou 1,540.10 - o grid retorna 154 ou 14501

No sqlClienteDataSet foi criado os fields:
VALOR DataType ftFMTBcd precision 32 e size 8

Li em um de meus livros que poderia fazer da sequinte forma

(sqlclientDataSet1.FieldByName('Valor') as
tFloatField).DisplayFormat:='###,###,###';

Porem o seguinte erro ?apresentado
Invalid Class typecast


Caso voc?possa me ajudar, fico muto agradecida.

Monica


 

Re:DBGrid

Obrigado por ter respondido. o problema estáva no nls_linguage no registre
do windows.
"Edgar Rodriguez" < XXXX@XXXXX.COM >wrote in message
Quote
Qu?Delphi estás usando?

Debes usar mejor el formato

#,##0.00

Disculpa el mensaje en español, pero no hablo portugues...


"Fernando(Brasil)" < XXXX@XXXXX.COM >escribi?en el mensaje
news: XXXX@XXXXX.COM ...
>Trabalho com oracle 9i e tenho que fazer um trabalho em delphi 7.
>
>Ao criar uma rotina de manutenção em uma de minhas tabelas através do
>DbGrid, obtenho um pequeno problema com campos float ou numeric(12,2).
Este
>ao ser exibido no grid, não possiona as casas decimais.
>
>Ex: valor - 1.54 ou 1,540.10 - o grid retorna 154 ou 14501
>
>No sqlClienteDataSet foi criado os fields:
>VALOR DataType ftFMTBcd precision 32 e size 8
>
>Li em um de meus livros que poderia fazer da sequinte forma
>
>(sqlclientDataSet1.FieldByName('Valor') as
>tFloatField).DisplayFormat:='###,###,###';
>
>Porem o seguinte erro ?apresentado
>Invalid Class typecast
>
>
>Caso voc?possa me ajudar, fico muto agradecida.
>
>Monica
>
>


 

Re:DBGrid

How can I put cells vertically?
Thanks in advance,
Catherine
 

Re:DBGrid

If you mean display a record in each column instead of a record in each
row the answer is that you cannot.
--
Bill Todd (TeamB)
TeamB cannot answer questions received via email
Catherine wrote:
Quote

How can I put cells vertically?

Thanks in advance,
Catherine
 

Re:DBGrid

If you really wanna, you could use a StringGrid. It is easy to use, but pay
attention on indexes :).
Rgds,
Lucian R.
"Catherine" < XXXX@XXXXX.COM >wrote in message
Quote

How can I put cells vertically?

Thanks in advance,
Catherine
 

Re:DBGrid

@ Bill
Thanks for answers.
@Lucian
Thanks for answers, too. I will analyze StringGrid. Have a look,example:
table1.cell[0,0]:='name'
table1.cell[1,0]:='adress'.
 

Re:DBGrid

Go get yourself copies of the JCL and JVCL libraries and then use a JvInspector, JvInspDB
to display Dataset data in a vertical grid.
jvcl.sourceforge.net/
sourceforge.net/projects/jcl/
Dennis Passmore
Ultimate Software, Inc.