PDA

Click to See Complete Forum and Search --> : DBlist Question


Rev. Michael L. Burns
Oct 16th, 2000, 07:09 AM
I have a DBList control 9dbListType)on one of my forms that displays to contents of a field in my database. The DBlist control is connected to a data control (datType). The capyion of the Data Control displays the current record.

As I step through the list using the data control everything works fine. However, if I click on an item in the list I would like the data control to move to that record. For instance, if the data control is currently at record 10 of 100, the 10th record is hilighted in the list control. However, if I now click on record 15 in the list control, although it now becomes hilighted, the data control remains at record 10. How can I get the record to reflect whatever record I click on in the DBList as well?

The problem is if I cycle through the list with the data control and delete a record it will delete the current record. However, it I move to record 15 in the DBList and the data control is still on record 10, then record 10 will be deleted, instead of the desired record 15 as hilighted in the dblist.

Sometimes it's easier to scroll through the list and select the record than it is to cycle through them with the data control.

Any help here would be most appreciated.

Rev. Michael L. Burns

HunterMcCray
Oct 16th, 2000, 09:58 AM
Originally posted by Rev. Michael L. Burns
I have a DBList control 9dbListType)on one of my forms that displays to contents of a field in my database. The DBlist control is connected to a data control (datType). The capyion of the Data Control displays the current record.

As I step through the list using the data control everything works fine. However, if I click on an item in the list I would like the data control to move to that record. For instance, if the data control is currently at record 10 of 100, the 10th record is hilighted in the list control. However, if I now click on record 15 in the list control, although it now becomes hilighted, the data control remains at record 10. How can I get the record to reflect whatever record I click on in the DBList as well?

The problem is if I cycle through the list with the data control and delete a record it will delete the current record. However, it I move to record 15 in the DBList and the data control is still on record 10, then record 10 will be deleted, instead of the desired record 15 as hilighted in the dblist.

Sometimes it's easier to scroll through the list and select the record than it is to cycle through them with the data control.

Any help here would be most appreciated.

Rev. Michael L. Burns

The easiest thing to do to ensure that your data bound list and your data control are in-sync is to use the data item's key in the .ItemData property of the list control. When you want to delete the record use an SQL statement to do the delete and then refresh your data control....

txtSQL = "DELETE........WHERE TableName.KeyField = dbList1.ItemData(dbList1.ListIndex)"

db.execute Sql

(Assumes that you have opened a data base connection called db)

The other way of handling this would be to attatch code to the click event of the List so that the data control was forced to move to the record that you clicked on.

Hope that this helps

Hunter

Rev. Michael L. Burns
Oct 17th, 2000, 08:39 AM
Thanks HunterMcCray.

I was thinking about the click event in the dblist but am confused how this could be done. Can you provide an example to work from?

Thanks,
Rev. Michael L. Burns

HunterMcCray
Oct 17th, 2000, 08:54 AM
Dear Rev Burns,

I do not use the dbList control. I use an unbound List control and I populate it from code. I think that you might be better off using the dbGrid control if you want to use bound controls. I know that it stays in-sync with the data control. Ie if you move to the next record in the recordset the dbgrid control responds and vice-versa.

Hope this helps,

Hunter

Rev. Michael L. Burns
Oct 17th, 2000, 09:14 AM
Thanks Hunter for the input. Have a nice day.

Rev. Michael L. Burns