OWL NExt - Knowledge Base

[ Home | Contents | Search | Next | Previous | Up ]

The way I use TListWindow in a dialog

Date: 11/30/99
Time: 1:13:40 AM

// 1. In the constructor of the dialog create the list window control
MyDialog::MyDialog (TWindow* parent, TResId resId, TModule* module)
: TDialog (parent, resId, module)
{
myListWindow = new TListWindow (this, IDC_MY_LISTWINDOW);
}

// 2. In the Virtual function SetupWindow of the dialog setup the list
window
MyDialog::SetupWindow()
{
TDialog::SetupWindow();

// OPTIONAL:
// If you have COMCTL32.DLL Version 4.70 or later then you can use the
// following extended features.
// grid, sub item images, check boxes, track select, drag header,
// full row select, one click activate and two click activate
// then add the following to the file "commctrl.h" in your BC
include
// directory
//
// commctrl.h (Don't add this if you have OWL6)
// #define LVS_EX_GRIDLINES 0x0001
// #define LVS_EX_SUBITEMIMAGES 0x0002
// #define LVS_EX_CHECKBOXES 0x0004
// #define LVS_EX_TRACKSELECT 0x0008
// #define LVS_EX_HEADERDRAGDROP 0x0010
// #define LVS_EX_FULLROWSELECT 0x0020
// #define LVS_EX_ONECLICKACTIVATE 0x0040
// #define LVS_EX_TWOCLICKACTIVATE 0x0080
//
// also add in this macro
// #define LVM_SETEXTENDEDLISTVIEWSTYLE (LVM_FIRST + 54)
// #define ListView_SetExtendedListViewStyle(hwnd, style) \
// (BOOL)SNDMSG((hwnd), LVM_SETEXTENDEDLISTVIEWSTYLE,
0,style)
//

//
// Let set myListWindow to have full row select
// NOTE: you can only set extend style after the list window is
created.
// Most of these extend styles only work when
myListWindow is
// Set to "report view".
ListView_SetExtendedListViewStyle (myListWindow->HWindow,
LVS_EX_FULLROWSELECT);

// Now set some column headers
TListWindColumn col0 ("File Name", 120, TListWindColumn::Left/*Align text
to left*/);
TListWindColumn col1 ("Size", 120, TListWindColumn::Center/*Align text to
center*/);
TListWindColumn col2 ("Date", 120, TListWindColumn::Right/*Align text to
right*/);

myListWindow->InsertColumn (0, col0);
myListWindow->InsertColumn (1, col1);
myListWindow->InsertColumn (2, col2);

// Now set some data into myListWindow
char fileName[10];
char date[10];
char size[10];

for (int i=0; i<5; i++) {
{
// Let's make up some data.
sprintf (fileName, "File%d", i);
sprintf (size, "%d", (2*i*i + 5*i + 20));
sprintf (date, "%02d/%02d/1999", ((i+1)%12), (((i+1)*5)%30) );

// Now create the item to insert into the first column -- col0
TListWindItem item(fileName);
// OPTIONAL: Now set the item data to point to something useful,
// like a record of some kind
item.SetItemData ((uint32)i);
// Now insert the item into myListWindow
// Item will be inserted to the end of the list unless
// you set the item index to something else (like item.SetIndex
(index))
// OR you have set the list window to SORT automatically then it
will
// insert into the right sort order.
// This function also return the index if you wish to know where it
inserted the item.
myListWindow->InsertItem (item);

// Now insert other data into other column.
// You need to set the mask to LVIF_TEXT to let the list window know
// that you are inserting text into the sub-columns.
item.mask = LVIF_TEXT;

// Now insert the size to the second column -- col1
item.SetText (size);
myListWindow->SetItem (item, -1, 1);

// Now insert the date to the third column -- col2
item.SetText (date);
myListWindow->SetItem (item, -1, 2);

}
// That's it. You have successfully create a list window
// with 3 columns and 5 rows of data.
// To add more data some where else, you just follow the above step.
}


// You can find out how many item is currently selected by
// calling GetSelCount(). This is a good way to check
// to see if there is any item currently selected.
int numSelCount = myListWindow->GetSelCount();

// You can iterate through the list to see which item is currently selected
for (int index=0; index<myListWindow->GetItemCount(); index++)
{
if (myListWindow->IsSelected (index))
// Do something here
else
// Skip or do somthing else here
}

// You can get the information at any row and at any column
// like this
TListWindow item (*myListWindow, row, column);
strcpy (TEXT, item.GetText());
// OR
TListWindow item;
item.SetIndex (row);
item.SetSubItem (column);
myListWindow->GetItem (item);
strcpy (TEXT, item.GetText());

// If you want to modify an item
// then find out the index of the item you want to modify.
TListWindow item;
item.SetIndex (index);
item.SetText ("New Text");
// if the item is in the first column then
myListWindow->SetItem (item, 0, 0);
// if the item is in the sub-column then
myListWindow->SetItem (item, -1, sub_column);

// you can catch the notification for an item when something has changed
// by using
EV_LVN_ITEMCHANGED
// Example
// DEFINE_RESPONSE_TABLE1 (MyDialog, TDialog)
// EV_LVN_ITEMCHANGED(IDC_MY_LISTWINDOW, MY_LISTWINDOW_LVNItemchanged)
// END_RESPONSE_TABLE
void MyDialog::MY_LISTWINDOW_LVNItemchanged (TLwNotify& notify)
{
int index = nofity.iItem;

if (myListWindow->IsSelected (index))
// Do somthing here
}


Last changed: July 14, 2001