Listbox select row populate Textfield

I populate my listbox with database records. I would like then to select a row and populate textfields with the information information. What is the best way to do this? I have 3 columns with indexed (why? not sure) A simple code example would be greatly appreciated. I am very frustrated, I know this has to be simple! I have reading and trying for 2 days, tired of beating my head. A little guidance would certainly be appreciated! Using real studio 2011 release 4. Thanks:)

PS…I am using the Textfields to edit the records.

In the listbox’s Change() event:

TextFieldForColumn0.Text = Me.Cell(Me.ListIndex, 0) TextFieldForColumn1.Text = Me.Cell(Me.ListIndex, 1) TextFieldForColumn2.Text = Me.Cell(Me.ListIndex, 2)

the listbox can do inline editing. just set the cells

listbox1.CellType(row,column)=ListBox.TypeEditable
listbox1.EditCell(row,column)

Inline editing i one way. The other - which gives some more flexibility - is to edit the data inside some textfields. To do this you must first check if there is a row in your listbox elected. If so, you can send the data into your Textfields / Areas. If there are Integer Fields you have to fencer your listbox values as listbox only stores text.

So use your .change event of your listbox to do something like this

if me.listindex <> -1 then // there is arrow selected

textfield1.text = me.cell(me.listindex, 0) // col 0 of your listbox
textfield2.text = me.cell(me.listindex, 1) // col 1 of your listbox…
textfield3.text = me.cell(me.listindex, 2)

end if

and so on

Getting your data back into your listbox depends on the moment when you store your data in your db. My way is a save into the db using the textfields. Much more simpler to check for plausibilities…

Another way is to send your data back to your listbox. One of the places to do this is the texfield.Textchange event.

if listbox1.listindex <> - 1 then // again - checking for a row selected
me.text = listbox1.cell(listbox1.listindex, 0) // or the col you need.
end if

Hope you can deal with that…

Christian

fencer? Must be my automatically correction… I mean convert…

You might want to look at control sets as well. That way you can link your x axis from the listbox to the control set index. It makes for a very simple mapping.

Isn’t there a risk, that this can get out of order if Columns and/or Textfields are added and removed?

When populating the listbox store recordID as rowtag(). I assume that you want more data in the fields than is shown in the listbox. Put in the change event of the listbox a sqlquery based upon the recordID that you retrieve with the rowtag(). Retrieve the data as recordset and fill the fields accordingly.

Thats how I do it. When the user scrolls through the listbox, all datafields get filled correctly.

1 Like