ravikirang
asked on
Listview control in ATL
hi to all,
I have to display values in Listview control using ALT. I tried with ListView_InsertColumn to add column header. It got displayed in listview. Where as when i tried to display a corresponding item using ListView_InsertItem to the list view control, I could't able to display it. Can any one suggest me how to display listview control in ATL if there is other way of doing so. The following is the code i have used.
HWND lvwhwnd;
lvwhwnd = m_ctlSysListView32.Create( m_hWnd, rc,_T("hello List View Control"), WS_TABSTOP | WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_AUTOARRANGE |LVS_REPORT | LVS_OWNERDATA,WS_EX_CLIENT EDGE, IDR_LISTVIEW);
LV_COLUMN lvColumn;
char* szString;
szString="PAGE URL";
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 200;
lvColumn.pszText = szString;
int val = ListView_InsertColumn(lvwh wnd, 0, &lvColumn);
LV_ITEM lvitem;
lvitem.mask = LVIF_TEXT;
//lvitem.iItem = 0;
//lvitem.iSubItem=0;
lvitem.pszText="My";
int han=ListView_InsertItem(lv whwnd,&lvi tem);
eagerly waiting for advise,
Thanks in advance,
ravi.
I have to display values in Listview control using ALT. I tried with ListView_InsertColumn to add column header. It got displayed in listview. Where as when i tried to display a corresponding item using ListView_InsertItem to the list view control, I could't able to display it. Can any one suggest me how to display listview control in ATL if there is other way of doing so. The following is the code i have used.
HWND lvwhwnd;
lvwhwnd = m_ctlSysListView32.Create(
LV_COLUMN lvColumn;
char* szString;
szString="PAGE URL";
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 200;
lvColumn.pszText = szString;
int val = ListView_InsertColumn(lvwh
LV_ITEM lvitem;
lvitem.mask = LVIF_TEXT;
//lvitem.iItem = 0;
//lvitem.iSubItem=0;
lvitem.pszText="My";
int han=ListView_InsertItem(lv
eagerly waiting for advise,
Thanks in advance,
ravi.
ASKER
Hi miqel Thanks for earliest reply,
But i tried even by removing coments but i could't able to see values of listview on control.
Please suggest me
ravi
But i tried even by removing coments but i could't able to see values of listview on control.
Please suggest me
ravi
Hi!
here is working example (in the DIALOG)
RECT rc;
LV_COLUMN lvc;
char szCaption[48];
::GetClientRect(m_hwndList , &rc);
LoadString(_Module.GetModu leInstance (), IDS_TEMPLATE, szCaption, sizeof(szCaption));
lvc.mask = LVCF_TEXT | LVCF_WIDTH |LVCF_SUBITEM |LVCF_FMT;
lvc.cx = 2*rc.right/5-2;
lvc.pszText = szCaption;
lvc.fmt = LVCFMT_LEFT | LVCFMT_IMAGE;
lvc.iSubItem = 0;
ListView_InsertColumn(m_hw ndList, 0, &lvc);
LoadString(_Module.GetModu leInstance (), IDS_CREATE_DATE, szCaption, sizeof(szCaption));
lvc.cx = rc.right/5;
lvc.fmt = LVCFMT_CENTER;
lvc.iSubItem = 1;
ListView_InsertColumn(m_hw ndList, 1, &lvc);
LoadString(_Module.GetModu leInstance (), IDS_CHECK_CAPTION, szCaption, sizeof(szCaption));
lvc.iSubItem = 2;
ListView_InsertColumn(m_hw ndList, 2, &lvc);
LoadString(_Module.GetModu leInstance (), IDS_SEND_CAPTION, szCaption, sizeof(szCaption));
lvc.iSubItem = 3;
ListView_InsertColumn(m_hw ndList, 3, &lvc);
// insert items
LV_ITEM lvi;
lvi.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_ PARAM|LVIF _STATE;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = "code";
lvi.state = nCount == 1 ? LVIS_SELECTED : 0;
lvi.stateMask = LVIS_SELECTED;
lvi.iImage = 1;
lvi.lParam = 0;
ListView_InsertItem(hList, &lvi);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 1;
lvi.pszText = "subitem 1";
ListView_SetItem(hList, &lvi);
lvi.iSubItem = 2;
lvi.pszText = "subitem 2";
ListView_SetItem(hList, &lvi);
here is working example (in the DIALOG)
RECT rc;
LV_COLUMN lvc;
char szCaption[48];
::GetClientRect(m_hwndList
LoadString(_Module.GetModu
lvc.mask = LVCF_TEXT | LVCF_WIDTH |LVCF_SUBITEM |LVCF_FMT;
lvc.cx = 2*rc.right/5-2;
lvc.pszText = szCaption;
lvc.fmt = LVCFMT_LEFT | LVCFMT_IMAGE;
lvc.iSubItem = 0;
ListView_InsertColumn(m_hw
LoadString(_Module.GetModu
lvc.cx = rc.right/5;
lvc.fmt = LVCFMT_CENTER;
lvc.iSubItem = 1;
ListView_InsertColumn(m_hw
LoadString(_Module.GetModu
lvc.iSubItem = 2;
ListView_InsertColumn(m_hw
LoadString(_Module.GetModu
lvc.iSubItem = 3;
ListView_InsertColumn(m_hw
// insert items
LV_ITEM lvi;
lvi.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = "code";
lvi.state = nCount == 1 ? LVIS_SELECTED : 0;
lvi.stateMask = LVIS_SELECTED;
lvi.iImage = 1;
lvi.lParam = 0;
ListView_InsertItem(hList,
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 1;
lvi.pszText = "subitem 1";
ListView_SetItem(hList, &lvi);
lvi.iSubItem = 2;
lvi.pszText = "subitem 2";
ListView_SetItem(hList, &lvi);
ASKER
Hi,
even i tried with this code, I could able to display the columm headings but the values are not getting displayed.
when i tried
int nval = ListView_InsertItem(hList, &lvi);
A value 0 is getting stored in nval. In documentaion it was
given that it returns a value if inserted else -1 will be returned. Please correct me if i'm wrong. Help me with alternative.
ravi
even i tried with this code, I could able to display the columm headings but the values are not getting displayed.
when i tried
int nval = ListView_InsertItem(hList,
A value 0 is getting stored in nval. In documentaion it was
given that it returns a value if inserted else -1 will be returned. Please correct me if i'm wrong. Help me with alternative.
ravi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thankyou miqel it is working after i removed LVS_OWNERDATA.
Thanks a lot once again,
ravi
Thanks a lot once again,
ravi
what for you comment these lines?
//lvitem.iItem = 0;
//lvitem.iSubItem=0;
uncomment it and try.