Page 1 of 1

PostPosted: Tue Mar 20, 2001 6:55 pm
by chrisfoster
How to you find out which record the user has selected on a tableDB in CControls? I tried to use the value returned by Cgercursel in Cgetfield, but that didn't seem to work.

example code
<pre id=code><font face=courier size=2 id=code>
int index;string x;
</font id=code></pre id=code>

In the above, does x have to be a pointer?

PostPosted: Wed Mar 21, 2001 2:06 am
by stephane
You only need Cgetcursel(), which returns the row (record) number that is currently selected within the tableDB control.

Cgetfield() will return the contents of the field within a given row.

There is no automatic way (at least not yet...) to get which field was selected by the user. You could do that yourself by getting the penx/peny after a row selection, and calculating it.



PostPosted: Fri Mar 23, 2001 12:37 am
by chrisfoster
but Cgetfield doesn't always work! Sometimes, it will just give me a 0 or something like that.

PostPosted: Fri Mar 23, 2001 1:31 am
by stephane
I should have been more explicit in my initial reply.. your code example is <i>not</i> correct. It should look more like this:
<pre id=code><font face=courier size=2 id=code>row=Cgetcursel(table);
if(row != -1 ) {
field1=Cgetcontent(table); // equivalent to Cgetfield(table, 0)
field2=Cgetfield(table, 1);
field3=Cgetfield(table, 2);
// etc...
</font id=code></pre id=code>

Cgetcursel() is only used to get the index, or row, already selected by the user, and in my example I used it to make sure something was actually selected. That is <i>all</i> it's used for. In other words, Cgetfield() does not need Cgetcursel() at all.. it uses whatever row is selected by the user, or whatever you select using C<i>set</i>cursel().

Also, Cgetfield() returns a <i>field</i>, or <i>column</i>, within the row; do not be misled by the original docs written for Ccontrols.
For Cgetfield(), it says that it gets a row; it does <i>not</i>. In several cases, the documentation says row when it means <i>column</i>. Strangely, the docs for Cgetcontent are correct, and state that it retrieves the first field in the row...
The author's mother tongue is German, which may explain some of the confusion <img src=icon_smile.gif border=0 align=middle>.

Hope this clarifies, if not, ask again.


PostPosted: Mon Mar 26, 2001 10:43 pm
by chrisfoster
OK, if I send the index returned by Cgetcursel() into dbseek, then it will select the right record, correct?

PostPosted: Tue Mar 27, 2001 1:49 am
by stephane
Yes, you are right, although the correct function would be dbrec(), not dbseek().

So, set dbrec() to the index returned by Cgetcursel(), and you can retrieve the entire record of information requested by a user, for example.

Seems that's the easiest way to explain, but in my last reply, it looks like I lost track that we were actually talking about database access, and not just the Ctable() control.. <img src=icon_smile.gif border=0 align=middle>



PostPosted: Tue Mar 27, 2001 7:40 pm
by chrisfoster
Thanks for your help - Chris