Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters > C/C++
Register

Reply
 
LinkBack Thread Tools
Old 01.06.2006, 16:40   #1
Младенец
 
Join Date: 04 2006
Location: Mauritius
Age: 34
Posts: 12
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default C++ Builder 6 - Getting a value from a DBGrid

Hi,
How can I do the following?
I have a DBGrid and I need to get values that grid.
When I click on a cell in the grid, I need to get all values in the selected row.
If for example there are 3 columns named ID, name and age.
If I click a cell in the grid, the value for the Id is displayed in a textbox, the value for name in another one and also the value for age in another textbox.
That is I need to display individual column values for the selected row in a text box for each one.
Can anyone help me?
Thanks.
Rowin
Reply With Quote
Old 02.06.2006, 04:54   #2
Академик
 
Join Date: 01 2002
Location: Shambala
Age: 38
Posts: 7,015
Downloads: 11
Uploads: 0
Reputation: 267 | 5
Default Re: C++ Builder 6 - Getting a value from a DBGrid

ape jan

Grid is just to show you the data you got from the database (in your dataset). It's not a good way of programming to get values directly from a grid.
You better get values from the dataset according your selection on the grid

so how can you do this.
first of all you need to put 3 components on your form: TDBGrid gr, TDataSource ds, and some data set let it be simple TQuery qr. You have to specify connections between these 3 components.
Thus set qr as a DataSet property in your ds
Set ds as a DataSource property in your gr

Now you have to specify a database and a table to select values from. Let it be a query like this "SELECT ID, NAME FROM TBL1"

now put an TEditBox txt component on your form
now you can use your gr's event OnCellClick and write this code there

txt->Text = qr->FieldByName("Name")->AsString;

ENJOY !
__________________
Ախպեր դու էմիգրացիան տուրիզմի հետ մի խառնի...

http://moskull.livejournal.com/
Reply With Quote
Old 02.06.2006, 06:14   #3
The splendid
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Pure thoughts
Age: 36
Posts: 3,408
Downloads: 22
Uploads: 0
Reputation: 222 | 3
Default Re: C++ Builder 6 - Getting a value from a DBGrid

This of course is a solution but complicated, the OP means how to retrieve data from grid by mouse selection (multiple?), so in this scenario he have to build the query string on the fly which could be complicated, but IMO he asked for the solution of getting selected data directly from the control, which might have a method of returning selected data directly without extra query.
__________________
The main achievements in applied research are due to fundamental science.
Reply With Quote
Old 02.06.2006, 06:34   #4
Академик
 
Join Date: 01 2002
Location: Shambala
Age: 38
Posts: 7,015
Downloads: 11
Uploads: 0
Reputation: 267 | 5
Default Re: C++ Builder 6 - Getting a value from a DBGrid

we do not offer to do extra query. if there is a datagrid which displays values , it means there WAS a query. i wrote just about that primary query. no need to do extra one man
Rowin is a junior in CBuilder, that's why i wrote everything so simplified from A to Z

otherwise i would've just written

write an event on CellClick

txt->Text = qr->FieldByName("Name")->AsString;

that's it

AND ONE MORE TIME

it's not the best way to select data from datagrid like this (for example)

txt->Text = gr->Columns->Column(0)->Field->Value;

it's the stupidest way the programmer can write
Reply With Quote
Old 02.06.2006, 06:47   #5
The splendid
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Pure thoughts
Age: 36
Posts: 3,408
Downloads: 22
Uploads: 0
Reputation: 222 | 3
Default Re: C++ Builder 6 - Getting a value from a DBGrid

I am not an expert in this field, but why? as long as it works
Reply With Quote
Old 02.06.2006, 16:50   #6
Младенец
 
Join Date: 04 2006
Location: Mauritius
Age: 34
Posts: 12
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: C++ Builder 6 - Getting a value from a DBGrid

Thanks a lot for the reply.

It worked.

Kind Regards,
Rowin
Reply With Quote
Old 06.11.2014, 15:45   #7
Младенец
 
Join Date: 11 2014
Location: Bosnia and Herzegovina
Posts: 2
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Builder c++ find text in DBGrid

Regards for all of you. I have a question about Borland Builder code.
I have Table1 with DataSource, conected on paradox.DB (inside that base are topics of my eBox saved in some folder).
Now I am using EditBox and Button to execute filter in DBGrid and I wanna make search to find a word or part of word (from EditBox) in multiple filles whereever is that word mentioned in my eBox colection (DBGrid).

All my eBox are in pdf format.
Is it possible??
Reply With Quote
Old 07.11.2014, 19:33   #8
Младенец
 
Join Date: 11 2014
Location: Bosnia and Herzegovina
Posts: 2
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default

Hello for everybody

Can someone help me to solve this problem:

I have a DBGrid in form conected to DataSource (DS is conected to the Table).
in DBGrid I have just one field1 and I wanna make search button using EditBox to find text inside in DBGrid

Now I can create code to search from the beging of row, but I wanna make a search code that can find text in any position of the row.

For example:
In row I have next text: I AM A SOLDIER

when I write in EditBox AM and click Button I wanna it find that row with rowselector

If someone can help, thank a lot.
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 03:16.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.