-
August 1st, 2003, 07:54 AM
#1
Multi Column ListBox
How can make a multicolumn list box (i know how to create it- but don't know how add columns and titles to them, and how to maintain).
(I'm not using MFC)
-
August 1st, 2003, 08:17 AM
#2
Why don't you create a list control instead of a multicolumn listbox ?
It would be easier to create and maintain it, because it features multiple columns already.
Multicolumn/owner-draw listboxes were useful only when we hadn't common controls (to say, Visual SourceSafe implements even a tree control with a list box).
-
August 1st, 2003, 09:22 AM
#3
Hmm, thanks, I've never thought of it. But i still don't know how to add a title though :/
-
August 2nd, 2003, 11:46 AM
#4
Is there any online tutorials/docs/code samples that demostrate creation and usage of multicolumn listboxes?
(I do not want to use MFC)
I'll be glad to see one...
-
August 2nd, 2003, 09:06 PM
#5
Use CListCtrl:
CListCtrl list;
list.InsertColumn(0,"Fist Column");
list.InsertColumn(1,"Second Column");//title between " "
...
I think it accomplishes your requirements.
-
August 2nd, 2003, 10:27 PM
#6
Originally posted by Cortez
Is there any online tutorials/docs/code samples that demostrate creation and usage of multicolumn listboxes?
(I do not want to use MFC)
I'll be glad to see one...
It would be very, very, very easy to simply add the style to a listbox in a test program and then add half a dozen or a dozen items. You will quickly see that it is a waste of time to do what you are asking to do.
Multicolumn listboxes don't work the way you think they do and therefore column headers are useless for them. Believe me; the multicolumn style for listboxes is not worth dwelling on.
CListCtrl For Beginners
Last edited by Sam Hobbs; August 2nd, 2003 at 10:30 PM.
-
August 3rd, 2003, 08:54 AM
#7
I purely remember saying that I do not want to use MFC.
-
August 4th, 2003, 05:07 AM
#8
Have a look at the following website:
ListView overview
Post here again if you need help.
-
August 11th, 2003, 06:48 AM
#9
OK Here I've created a multi column textbox. Now how do I add items to a specified column?
Code:
DWORD dwStyle = WS_TABSTOP |
WS_CHILD |
WS_BORDER |
WS_VISIBLE |
LVS_AUTOARRANGE |
LVS_REPORT ;
//LVS_OWNERDATA;
// Create the main listbox
hwndListView = CreateWindowEx( WS_EX_CLIENTEDGE, // ex style
WC_LISTVIEW, // class name - defined in commctrl.h
"", // dummy text
dwStyle, // style
0, // x position
0, // y position
0, // width
0, // height
hwnd, // parent
(HMENU)ID_LISTVIEW, // ID
hInstance, // instance
NULL); // no extra data
if(hwndListView == NULL)
{
// some error handling
}
LV_COLUMN lvColumn;
int i;
TCHAR szString[3][30] = {"Hello", "One", "Two"};
//initialize the columns
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 108;
for(i = 0; i < 3; i++)
{
lvColumn.pszText = szString[i];
ListView_InsertColumn(hwndListView, i, &lvColumn);
}
//empty the list
ListView_DeleteAllItems(hwndListView);
// a function that corrects the listview's width/height
ResizeListView(hwndListView, hwnd);
-
August 11th, 2003, 12:26 PM
#10
That is not a "multi column textbox". There is not a "multi column textbox" in the Windows SDK. The documentation has the name of it and has examples of adding items.
-
August 12th, 2003, 10:07 AM
#11
I know that there'S no multi-column textbox, I mistyped. I meant multi column listview.
I have MSDN cds, but can't find the example of how to add items in desired columns. This is why I posted a message to this forum, expecting a help.
-
August 12th, 2003, 10:43 AM
#12
Look at Windows Controls. That is an online copy of something you probably have in your local hard drive. In the "List-View" documentation there is a sample program for it. If you have the Platform SDK installed then the sample programs probably have other samples also. With the samples installed in a local hard drive (the default when the SDK is installed) the source files can be searched and many useful things can be found.
-
August 13th, 2003, 03:28 PM
#13
I already looked the example that is reached from the link you gave, and it ues VIRTUAL multicolumn list view, NOT multi column listview.
If you read the code I wrote, you could esliy see this too. It's better not to hear advices on usage of MSDN, because it's nothing but a timeloss.
You could write a small piece of code that adds an item to the listview I created above, and this thread would end. I'll be happy if someone says something that I don't know about the thing I asked .
-
August 13th, 2003, 04:06 PM
#14
I sure don't understand why it is so difficult to use the following as an example.
Code:
typedef struct tagPETINFO
{
char szKind[10];
char szBreed[50];
char szPrice[20];
}PETINFO;
// A PETINFO variable is declared and initialized as
// follows:
PETINFO rgPetInfo[ ] =
{
{"Dog", "Poodle", "$300.00"},
{"Cat", "Siamese", "$100.00"},
{"Fish", "Angel Fish", "$10.00"},
};
// Some code to create the list-view control.
// Initialize LVITEM members that are common to all
// items.
lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
lvI.state = 0;
lvI.stateMask = 0;
// Initialize LVITEM members that are different for each item.
for (index = 0; index < 3; index++)
{
lvI.iItem = index;
lvI.iImage = index;
lvI.iSubItem = 0;
lvI.lParam = (LPARAM) &rgPetInfo[index];
lvI.pszText = LPSTR_TEXTCALLBACK; // sends an LVN_GETDISP message.
if(ListView_InsertItem(hWndListView, &lvI) == -1)
return NULL;
}
Last edited by Sam Hobbs; August 13th, 2003 at 04:08 PM.
-
June 2nd, 2004, 07:40 AM
#15
The following code will fill in a list box with 8 subitems. No MFC used. Hope this helps. If you need more, e-mail me at Aptom@softhome.net
LVITEM listItem;
listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE | LVIF_DI_SETITEM;
listItem.state = 0;
listItem.stateMask = 0;
for(int i = 0; i < numClients; i++)
{
listItem.iItem = i;
listItem.iImage = i;
listItem.iSubItem = 0;
listItem.lParam = (LPARAM) NULL;
listItem.pszText = clientList[i].insuranceCompany; // sends an LVN_GETDISPINFO message
ListView_InsertItem(listViewHandle, &listItem);
LVITEM subItem;
subItem.iItem = i;
subItem.iSubItem = 1;
subItem.mask = LVIF_TEXT;
subItem.pszText = clientList[i].name;
ListView_SetItem(listViewHandle, &subItem);
subItem.iItem = i;
subItem.iSubItem = 2;
subItem.mask = LVIF_TEXT;
sprintf(buffer, "%.2f", clientList[i].annualPremium);
subItem.pszText = buffer;
ListView_SetItem(listViewHandle, &subItem);
subItem.iItem = i;
subItem.iSubItem = 3;
subItem.mask = LVIF_TEXT;
sprintf(buffer, "%.2f", clientList[i].modalPremium);
subItem.pszText = buffer;
ListView_SetItem(listViewHandle, &subItem);
subItem.iItem = i;
subItem.iSubItem = 4;
subItem.mask = LVIF_TEXT;
subItem.pszText = clientList[i].modalPaymentType;
ListView_SetItem(listViewHandle, &subItem);
subItem.iItem = i;
subItem.iSubItem = 5;
subItem.mask = LVIF_TEXT;
subItem.pszText = clientList[i].paidThroughMonth;
ListView_SetItem(listViewHandle, &subItem);
subItem.iItem = i;
subItem.iSubItem = 6;
subItem.mask = LVIF_TEXT;
subItem.pszText = clientList[i].effectiveDate;
ListView_SetItem(listViewHandle, &subItem);
subItem.iItem = i;
subItem.iSubItem = 7;
subItem.mask = LVIF_TEXT;
sprintf(buffer, "%.2f", clientList[i].commission);
subItem.pszText = buffer;
ListView_SetItem(listViewHandle, &subItem);
subItem.iItem = i;
subItem.iSubItem = 8;
subItem.mask = LVIF_TEXT;
sprintf(buffer, "%.2f", clientList[i].ytdCommission);
subItem.pszText = buffer;
ListView_SetItem(listViewHandle, &subItem);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|