CListCtrl
Ed Bruck -- Ed.Bruck@Newnes.COM Monday, July 17, 1995 Does anybody know where I can find a good MFC sample for the List View control? TIA Ed ---------------------------------------------------- ====== Ed Bruck NEWNES Programmer/Analyst, Windows NT Administrator ====== Newnes Machine Ltd. Salmon Arm, British Columbia email: Ed.Bruck@Newnes.Com ebruck@noif.ncp.bc.ca 70673.155@compuserve.com ----------------------------------------------------
Mario Contestabile -- Mario_Contestabile.UOS__MTL@UOSMTL2.universal.com Friday, December 15, 1995 I have a CListCtrl in a dialog with items lined up side by side. Is there a way to decrease the spacing between those items? Since the spacing between the items is longer than the items themselves, it makes for a strange look. mcontest@universal.com
Karunakaran KR -- cs1@sriven.scs.co.in Thursday, March 06, 1997 Environment: VC++ 4.2b, Win 95, NT 4.0 Hi, Could anyone help me out in enabling a particular record in ClistCtrl like "SetCurSel" property in a ListBox.If possible please send me some sample code. Thanks in Advance, Rajneesh
Mario Contestabile -- Mario_Contestabile.UOS__MTL@UOSMTL2.universal.com Thursday, March 06, 1997 [Mini-digest: 8 responses] >Could anyone help me out in enabling a particular record in >ClistCtrl like "SetCurSel" property in a ListBox.If possible please >send me some sample code. m_ListCtrl.SetItemState(nItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F); mcontest@universal.com -----From: Regis NICOLASAt 10:03 AM 3/6/97 -0500, you wrote: >Environment: VC++ 4.2b, Win 95, NT 4.0 > >Hi, >Could anyone help me out in enabling a particular record in >ClistCtrl like "SetCurSel" property in a ListBox.If possible please >send me some sample code. > >Thanks in Advance, >Rajneesh > > Have a look to SetItemState(..., LVIS_SELECTED, LVIS_SELECTED); Hope this helps... Regis ------------------------------ Regis NICOLAS - R&D Windows Smartcode Technologie mailto:nicolas@smartcode.fr http://www.smartcode.fr/ http://www.smartcodesoft.com/ Tel.: (33) (0)4 67 59 30 16 -----From: Ajay K Sanghi Hi, You can try this code. this should work. LV_ITEM lvItem; lvItem.mask = LVIF_STATE; lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; lvItem.state = LVIS_SELECTED | LVIS_FOCUSED; lvItem.iItem = nItem; lvItem.iSubItem = 0; m_ListCtrl.SetItem( &lvItem ); Bye, Ashok On Thu, 6 Mar 1997, Rajneesh wrote: > Environment: VC++ 4.2b, Win 95, NT 4.0 > > Hi, > Could anyone help me out in enabling a particular record in > ClistCtrl like "SetCurSel" property in a ListBox.If possible please > send me some sample code. > > Thanks in Advance, > Rajneesh > > -----From: ktm@ormec.com On mfc-l, Rajneesh wrote: > Could anyone help me out in enabling a particular record in > ClistCtrl like "SetCurSel" property in a ListBox. Hmm. This isn't exactly an "intermediate or advanced" question... You need to use CListCtrl::SetItem. E.g. // m_ListCtrl is your list control // nItemToSelect is the 0-based index of the item you want to select LV_ITEM lvitem; ZeroMemory(&lvitem, sizeof(lvitem)); lvitem.mask = LVIF_STATE; lvitem.item = nItemToSelect; lvitem.state = LVIS_FOCUSED | LVIS_SELECTED; lvitem.stateMask = LVIS_FOCUSED | LVIS_SELECTED; m_ListCtrl.SetItem(&lvitem); Katy -- Katy Mulvey <mailto:ktm@ormec.com> Software Development Engineer ORMEC Systems -----From: "Eric Rosenquist" On 6 Mar 97 at 10:03, Rajneesh wrote: > Could anyone help me out in enabling a particular record in > ClistCtrl like "SetCurSel" property in a ListBox.If possible please > send me some sample code. Try: someListCtrl.SetItemState(itemIndex, LVIS_SELECTED, LVIS_SELECTED); Note that you'll need to make sure the list control is in single-select mode if you want it to de-select any other selected items. Use LVS_SINGLESEL when you create the list if this is the behaviour you want. Eric --------------------------------------------------------------------- Eric Rosenquist, Strata Software Limited http://www.strataware.com/ mailto:rosenqui@strataware.com Tel: 613-591-1922 Fax: 613-591-3485 Quote: God bless those pagans. -- Homer Simpson --------------------------------------------------------------------- -----From: Shane Triem If you're not already doing so, it is better to create a structure that encapsulates all the fields of a row. When you want to add rows to the list control, dynamically create an instance of the structure, initialize each member of the structure with the field data, then use the version of CListCtrl::InsertItem() that allows you to specify a 32-bit application specific value associated with the item (row). Set this value to the address of the dynamically created structure. (Make sure that when you delete items from the control that the dynamically created structures of the corresponding rows are also deleted so you don't have memory leaks!) With this all said and done, to select a particular row, start at the first row and cycle through each item in the list control using GetItem(). GetItem returns a pointer to the item added including the 32-bit application-specific data which is your data structure. Cast it to the structure type and use the contents of the structure to determine if the row should be selected. Below is sample code that I used to cycle through my list control. I have a member variable which is a list control (m_OrdersListCtrl) and the structure type that contains my field values is called OEP_ITEMINFO. LV_ITEM Item; ZeroMemory(&Item, sizeof(LV_ITEM); Item.mask = LVIF_PARAM | LVIF_STATE; OEP_ITEMINFO* pItemInfo; int iLastItemIndex = m_OrdersListCtrl.GetItemCount() - 1; for (int iItemIndex = 0; iItemIndex <= iLastItemIndex; iItemIndex++) { Item.iItem = iItemIndex; if (m_OrdersListCtrl.GetItem(&Item)) { pItemInfo = (OEP_ITEMINFO*)Item.lParam; if (pItemInfo->SomeField == ValueOfInterest) { // Set selected state of item Item.state |= LVIS_SELECTED; VERIFY(m_OrdersListCtrl.SetItem(&Item)); } } } If you know the particular row that needs to be selected, use the following code: LV_ITEM Item; ZeroMemory(&Item, sizeof(LV_ITEM); Item.mask = LVIF_STATE; Item.iItem = IndexOfItemOfInterest; // <----- Fill in with appropriate value m_OrdersListCtrl.GetItem(&Item); Item.state |= LVIS_SELECTED; m_OrdersListCtrl.SetItem(&Item); (I am assuming that you are using the list control in report mode) Hope this helps.. Shane Triem STEP Technology Portland, OR. shane@steptech.com ---------- From: Rajneesh Sent: Friday, March 07, 1997 12:10 AM To: SHANE; 'MFC-L@SMTP ' Subject: CListCtrl Environment: VC++ 4.2b, Win 95, NT 4.0 Hi, Could anyone help me out in enabling a particular record in ClistCtrl like "SetCurSel" property in a ListBox.If possible please send me some sample code. Thanks in Advance, Rajneesh -----From: "Kenneth A. Argo" Try this out for size: // Select item if the caller wants it selected m_cListControl.SetItemState(iActualItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); m_cListControl.EnsureVisible(iActualItem, FALSE); Ken ---------- From: Rajneesh[SMTP:cs1@sriven.scs.co.in] Sent: Thursday, March 06, 1997 10:04 AM To: mfc-l@netcom.com Subject: CListCtrl Environment: VC++ 4.2b, Win 95, NT 4.0 Hi, Could anyone help me out in enabling a particular record in ClistCtrl like "SetCurSel" property in a ListBox.If possible please send me some sample code. Thanks in Advance, Rajneesh -----From: ASalem_Ideal@nets.com.jo (Asila Salem) Hello, If you're having problems setting the state of an item in a dialog list control, try SetItem(): CListCtrl* plcTheList = (CListCtrl*)GetGlgItem(IDC_LIST); LV_ITEM lvItem; lvItem.iItem = nIndex; lvItem.mask = LVIF_STATE; lvItem.stateMask = LVIS_SELECTED; lvItem.state = LVIS_SELECTED; //0 to deselect. bOK = plcTheList->SetItem(&lvItem); Otherwise, simply call: bOK = SetItemState(nIndex, LVIS_SELECTED /*0 to deselect*/, LVIS_SELECTED); Asila Salem Senior Software Developer IdealSoft, Jordan ASalem_Ideal@nets.com.jo
Jason Healy -- jason@hkjcs.oz.au Monday, March 17, 1997 [Mini-digest: 2 responses] The first step is to derive your own CListCtrl class CListCtrlTT : public CListCtrl { } Add the following members: CToolTipCtrl m_tooltip; void AddTip(int nColumn, LPCTSTR lpszText); Override the following functions (use classwizard) and implement as follows BOOL CListCtrlTT::PreTranslateMessage(MSG* pMsg) { m_tooltip.RelayEvent(pMsg); return CListCtrl::PreTranslateMessage(pMsg); } void CListCtrlTT::PreSubclassWindow() { CListCtrl::PreSubclassWindow(); CHeaderCtrl * ph = (CHeaderCtrl *)GetDlgItem(0); m_tooltip.Create(this); m_tooltip.Activate(TRUE); } Implement the extra function AddTip() void CListCtrlTT::AddTip(int nColumn, LPCTSTR lpszTip) { CRect rc; CHeaderCtrl * ph = (CHeaderCtrl *)GetDlgItem(0); ph->GetClientRect(rc); rc.right = 0; LV_COLUMN lvc; lvc.mask = LVCF_WIDTH; for (int nCol = 0; nCol <= nColumn; nCol++) { rc.left = rc.right; GetColumn(nCol, &lvc); rc.right = rc.left + lvc.cx; } m_tooltip.AddTool(ph, lpszTip, rc, 1); } In your dialog class use the following: CMyDialog::OnInitDialog() { //.......as before m_ListTT.SubclassDlgItem(IDC_LIST1, this); m_list.InsertColumn(0, "Column 1", LVCFMT_LEFT, 60); m_list.InsertColumn(1, "Column 2", LVCFMT_LEFT, 60); m_list.AddTip(0, "Tip 1"); m_list.AddTip(1, "Tip 2"); return TRUE; } You now get tooltips. However this code still needs some work as to allow the column widths to be re-adjusted. But this will get you going. Jason Jason@hkjcs.oz.au ---------- > > Environment: VC++ 4.2b, Win 95, NT 4.0 > > Hi, > I have a problem of invoking a CToolTipCtrl on the header of the List > Control which is > in a REPORT MODE style.I want to generate a seperate tooltip message for > each column in > the HeaderControl.Could anyone help me out in solving this problem and send > me the sample code if possible. > > Thanks in Advance, > Rajneesh Sharma > -----From: "Jason Healy"Further to ealier mail, if you get stuck changing the tooltip positions when the column widths change try the following BOOL CListCtrlTT::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { BOOL bRet = CListCtrl::OnNotify(wParam, lParam, pResult); NMHDR* pnmhdr = (NMHDR*)lParam; if (pnmhdr->code == HDN_ITEMCHANGEDA || pnmhdr->code == HDN_ITEMCHANGEDW) { HD_ITEM * phdi = ((HD_NOTIFY*)lParam)->pitem; CRect rc; CHeaderCtrl * ph = (CHeaderCtrl *)GetDlgItem(0); ph->GetClientRect(rc); rc.right = 0; LV_COLUMN lvc; lvc.mask = LVCF_WIDTH; for (int nCol = 0; nCol < ph->GetItemCount(); nCol++) { rc.left = rc.right; GetColumn(nCol, &lvc); rc.right = rc.left + lvc.cx; m_tooltip.SetToolRect(ph, nCol + 1, rc); } } return bRet; } Notice this isn't that effiecint as it recalculates the rectangles for each column, when it need only do this for the preceeding column to the one that has been changed, and all successive columns. Jason jason@hkjcs.oz.au ---------- > > Environment: VC++ 4.2b, Win 95, NT 4.0 > > Hi, > I have a problem of invoking a CToolTipCtrl on the header of the List > Control which is > in a REPORT MODE style.I want to generate a seperate tooltip message for > each column in > the HeaderControl.Could anyone help me out in solving this problem and send > me the sample code if possible. > > Thanks in Advance, > Rajneesh Sharma >
Hieu Nguyen -- nguyen_hieu@geocities.com Monday, March 24, 1997 I followed the example, every thing worked fine, except I couldn't trap OnNotify message as Jason Healy describe. May someone provide more information. Thanks in advance. Jason Healy wrote: > > Postage paid by: > > --------------------------------------------------------------- > > [Mini-digest: 2 responses] > > The first step is to derive your own CListCtrl > > class CListCtrlTT : public CListCtrl { > } > > Add the following members: > > CToolTipCtrl m_tooltip; > void AddTip(int nColumn, LPCTSTR lpszText); > > Override the following functions (use classwizard) and implement as follows > > BOOL CListCtrlTT::PreTranslateMessage(MSG* pMsg) > { > m_tooltip.RelayEvent(pMsg); > return CListCtrl::PreTranslateMessage(pMsg); > } > > void CListCtrlTT::PreSubclassWindow() > { > CListCtrl::PreSubclassWindow(); > > CHeaderCtrl * ph = (CHeaderCtrl *)GetDlgItem(0); > > m_tooltip.Create(this); > m_tooltip.Activate(TRUE); > } > > Implement the extra function AddTip() > > void CListCtrlTT::AddTip(int nColumn, LPCTSTR lpszTip) > { > CRect rc; > CHeaderCtrl * ph = (CHeaderCtrl *)GetDlgItem(0); > ph->GetClientRect(rc); > rc.right = 0; > > LV_COLUMN lvc; lvc.mask = LVCF_WIDTH; > for (int nCol = 0; nCol <= nColumn; nCol++) { > rc.left = rc.right; > GetColumn(nCol, &lvc); > rc.right = rc.left + lvc.cx; > } > m_tooltip.AddTool(ph, lpszTip, rc, 1); > } > > In your dialog class use the following: > > CMyDialog::OnInitDialog() > { > //.......as before > m_ListTT.SubclassDlgItem(IDC_LIST1, this); > m_list.InsertColumn(0, "Column 1", LVCFMT_LEFT, 60); > m_list.InsertColumn(1, "Column 2", LVCFMT_LEFT, 60); > > m_list.AddTip(0, "Tip 1"); > m_list.AddTip(1, "Tip 2"); > > return TRUE; > } > > You now get tooltips. However this code still needs some work as to allow > the column widths to be re-adjusted. But this will get you going. > > Jason > Jason@hkjcs.oz.au > > -----From: "Jason Healy"> > Further to ealier mail, if you get stuck changing the tooltip positions > when the column widths change > try the following > > BOOL CListCtrlTT::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) > { > BOOL bRet = CListCtrl::OnNotify(wParam, lParam, pResult); > > NMHDR* pnmhdr = (NMHDR*)lParam; > > if (pnmhdr->code == HDN_ITEMCHANGEDA || pnmhdr->code == HDN_ITEMCHANGEDW) > { > > HD_ITEM * phdi = ((HD_NOTIFY*)lParam)->pitem; > > CRect rc; > CHeaderCtrl * ph = (CHeaderCtrl *)GetDlgItem(0); > ph->GetClientRect(rc); > rc.right = 0; > > > LV_COLUMN lvc; lvc.mask = LVCF_WIDTH; > for (int nCol = 0; nCol < ph->GetItemCount(); nCol++) { > rc.left = rc.right; > GetColumn(nCol, &lvc); > rc.right = rc.left + lvc.cx; > m_tooltip.SetToolRect(ph, nCol + 1, rc); > } > } > > return bRet; > } > Notice this isn't that effiecint as it recalculates the rectangles for each > column, when it need only do this for the preceeding column > to the one that has been changed, and all successive columns. > > Jason > jason@hkjcs.oz.au >
Karunakaran KR -- cs1@sriven.scs.co.in Tuesday, March 25, 1997 Environment: VC++ 4.2b, Win 95, NT 4.0 Hi , I have a owner drawn CListCtrl which is in REPORT MODE.I want to trap the event when the user drags the Horizontal scroll bar or Vertical Scroll bar.Could anyone help me in trapping the event. Thanx in Advance, Rajneesh
Dicky Singh -- Dicky@landmark.com Wednesday, March 26, 1997 [Mini-digest: 2 responses] In short, subclass the listctrl, write a handler for WM_VSCROLL and/or WM_HSCROLL In MFC (or now known as MFC&T), derive a class from CListCtrl, e.g. CListCtrl2, using the class wizard. Add a member variable m_List (e.g.) in the dialog of type CListCtrl2 In your dialog's initdialog, add following before call to base class m_List.SubclassDlgItem(IDC_LIST1, this); CDialog::OnInitDialog(); //\\// In CListCtrl2, add a handler OnVScroll (WM_VSCROLL) ---------- Dicky Singh Phoenix Development Team http://Ourworld.Compuserve.COM/homepages/dicky -----Original Message----- From: Rajneesh [SMTP:cs1@sriven.scs.co.in] Sent: Tuesday, March 25, 1997 1:22 AM To: mfc-l@netcom.com Subject: CListCtrl Environment: VC++ 4.2b, Win 95, NT 4.0 Hi , I have a owner drawn CListCtrl which is in REPORT MODE.I want to trap the event when the user drags the Horizontal scroll bar or Vertical Scroll bar.Could anyone help me in trapping the event. Thanx in Advance, Rajneesh -----From: Sreekant SreedharanRajneesh wrote: > > Environment: VC++ 4.2b, Win 95, NT 4.0 > > Hi , > > I have a owner drawn CListCtrl which is in REPORT MODE.I want to trap the > event when the user drags > the Horizontal scroll bar or Vertical Scroll bar.Could anyone help me in > trapping the event. > > Thanx in Advance, > Rajneesh > > I think writing handlers for WM_HSCROLL & WM_VSCROLL will do. -- - From Sreekant Sreedharan
Become an MFC-L member | Вернуться в корень Архива |