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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the index of a listbox to a _bstr_t value using ADO !!!

Status
Not open for further replies.

chriscorran

Programmer
Oct 20, 2002
15
GB
Hi,

I am learning ADO and can fill a list box with information from a database.

The problem is that as I add information to the list box I want the index of that line of information to be set to a specific value. ie. A value (id) from the database. The reason for this is so I can double click the list get the id for that line of information and display full details for that item based on teh id (index).

ie.
Fill list with

Chris blaaa
Bob blueee
jim josey
Tom Penny


Double click "jim". jims index (id) could be 67 so I'd search for all jims details based on his id (index).

I assume the index has to be an int and have tried

atoi((char*)_bstr_t(id));

_bstr_t(id) being the value pulled out of the database.

Why won't it work?????? Help please!!!!

A quick snippet of code would be great !!!!!!

Cheers in advance

 
Are you sure that the ID number of your records are stored in a string in the database?

By the way:
Maybe it's just a mistype in your post, but ItemData is used for storing extra information (usually for the purpose of what you're seeking). You cannot set the index; the index is the ordinal position of the value in the listbox.
Greetings,
Rick
 
My ADO module uses the following code to handle bookmarks - good luck.

DWORD Position;
_variant_t VarBookmark;

// Get the ADO record bookmark and save it in list box
// control
VarBookmark=pRcdSet->Bookmark;
Position=(long) VarBookmark;
ListBoxCtrl.SetItemData(i, Position);

---------------------------------------------------


// Retrieve ADO bookmark from list box control
Position=ListBoxCtrl.GetItemData(i);

// Initialize vt portion of variant field by getting
// current recordset location
VarBookmark=pRcdSet->Bookmark;

// Set new ADO location from list box's bookmark
VarBookmark= (double) BookMark;
pRcdSet->Bookmark=VarBookmark;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top