May 20, 2019
Hot Topics:

Adding Database Attribute Rows to the List Control

  • November 12, 2004
  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

The first item to add is the database name. This was returned in the CEOIDINFO structure member CEDBASEINFO's szDbaseName member. The returned name string is in Unicode, so you have to translate it to multibyte character format before inserting it in the list control. After translation, set the address of the MBCS string in lvitem.pszText, and call InsertItem().

//add attribute string to bottom row of the listctl
//loop thru the subitems
char szTempBuff[512];

lvitem.iSubItem = 0;
wcstombs(szTempBuff, poidInfo->infDatabase.szDbaseName,
lvitem.pszText = szTempBuff;

The next step is a key strategy. It helps optimize performance and makes opening the database to enumerate its records a bit more convenient. Set the OID value for this database as item data in the list control cell that holds the database name. Here's why you do this:

CE object identifiers are permanent attributes of the objects they identify. Put another way, they are created when the object is created, and stick with the same object throughout its lifetime. They are worth preserving because you can open a database (or a file) by CEOID as well as by name. Preserving the CEOID allows you to open the database without having to translate the name string in the list control back to Unicode. Also, opening the database by CEOID is a good bit faster than opening by name.

After the item has been added, set its item data like this:

//save the CEOID for this database in item data
ListCtrl.SetItemData( lvitem.iItem, (DWORD)enumCeoid );

Now, add the rest of the database attributes to the row. All you really have to do differently for the successive items is increment the lvitem.iSubItem, de-reference the applicable member of the CEDBASEINFO structure, and format the datum using sprintf().

lvitem.iSubItem = 1;
sprintf( szTempBuff, "%li", poidInfo->infDatabase.dwDbaseType);
lvitem.pszText = szTempBuff;

lvitem.iSubItem = 2;
sprintf( szTempBuff, "%x", poidInfo->infDatabase.dwFlags);

lvitem.iSubItem = 3;
sprintf( szTempBuff, "%i", poidInfo->infDatabase.wNumRecords);

lvitem.iSubItem = 4;
sprintf( szTempBuff, "%li", poidInfo->infDatabase.dwSize);

lvitem.iSubItem = 5;
CTime ctLastWrite(poidInfo->infDatabase.ftLastModified );
CString csLastWrite = ctLastWrite.Format("%A, %B %d, %Y" );
sprintf( szTempBuff, "%s", csLastWrite.GetBuffer
       ( csLastWrite.GetLength()));

lvitem.iSubItem = 6;
sprintf( szTempBuff, "%x", enumCeoid);


Looking Ahead

Having the mechanics of adding a row to the list control in hand, you are ready to retrieve records from the CE database. I'll show you how to do that in the next installment.

About the Author

Nancy Nicolaisen is a software engineer who has designed and implemented highly modular Windows CE products that include features such as full remote diagnostics, CE-side data compression, dynamically constructed user interface, automatic screen size detection, and entry time data validation.

In addition to writing for Developer.com, she has written several books, including Making Win 32 Applications Mobile.

# # #

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date