Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Correct me please, Click to display row data from grid into text-boxes

Status
Not open for further replies.

Yosua

Programmer
Aug 23, 2011
25
Hi,
I've been trying to show a row data from a grid back into text-boxes,
Here's what I do

Form Method "show_data"
Code:
THISFORM.txt_id.value = tb_member.id
THISFORM.txt_name.value = tb_member.name
THISFORM.txt_birthday.value = tb_member.birthday
THISFORM.txa_address.value = tb_member.address

Grid Click
Code:
thisform.show_data

And my problem is I only return the data from top row to text-boxes, and whenever I click the other row, it shows the data from the top row. Has anyone know where I did wrong and how to fix it?
Any suggestions are appreciated and sorry for bad english.

Regards
Yosua

 
Is tb_member really the table shown in the grid? Also Grid.click may be too early, record pointer has moved to the clicked line in Grid.AfterRowColChange Event, that happens, after the row has changed.

Why not use Textbox.Controlsources? That way you don't need any code, but perhaps do THISFORM.Refresh() in Grid.AfterRowColChange. That's all.

You set txt_id.Controlsource = "tb_member.id" etc. and the textboexes are bound to these table fields, like the grid is bound to the whole table via it's Recordsource.

Bye, Olaf.
 
Yosua, you need to do two things:

1. Put the call to thisform.show_data in the grid's AfterRowColChange, not in its Click; and

2. Put THISFORM.Refresh at the end of the Show_Data method.

I think that'lll fix it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks Olaf for the right solution, but if I may ask some more stupid question,
where should I put txt_id.Controlsource = "tb_member.id" should I set it on properties> and how it should work when I select a row on the grid to edit or delete?
Sorry for totally clueless about this.
 
Thanks Mike, I already have these in the grid's AfterRowColChange
Code:
LPARAMETERS nColIndex
thisform.tampil_data
I've tried it and it didn't work for me, did I do something wrong?
 
Oops sorry my bad.
Code:
LPARAMETERS nColIndex
thisform.show_data
 
After some trial and error, Mike's solution is working for me.
Thanks Mike you're a lifesaver. I should learn about control source too, thanks Olaf
 
Yes, you can set controlsources in property window at design time. If you have a Dateenvironment with the table, simply drag from a single field to the form, and you'll get a textbox with controlsource already set.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top