15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CListCtrl Question

Gary_Shank@dublin.sterling.com
Saturday, April 01, 1995

     I'm trying to implement a simple "report-type" CListCtrl inside a 
     CScrollView for a 32bit MDI application using MSVC 2.1 and NT 3.51.  
     So far, I've got the column headers the way I want and I'm getting 
     data to show up in the list items....but.....I'm not getting a full 
     selection highlight bar across all columns and I'm only able to select 
     in the first column.  And how do I get double-click events from the 
     mouse when positioned on an item line?  I've looked at the ListView 
     sample on the developer CD (which is how I got to where I'm at now) 
     but I can't find any other examples.
     
     My CListCtrl class was created with the following:
     WS_VISIBLE | WS_CHILD | LVS_NOSORTHEADER | LVS_REPORT | LVS_SINGLESEL;
     
     My column mask is:
     LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
     
     My item mask is:
     LVIF_STATE;
     
     The functionality I'm looking for is just like a normal listbox except 
     for the resizable columns/headers.
     Gary




Hector Fabio RESTREPO -- restrepo@di.epfl.ch
Friday, September 13, 1996

Environment: VC++ 4.0, Windows NT 3.51

I am writing an application where one of the windows displays the
information contained in a memory. The information on the window
looks like :

Address       LB   HB    Data
----------------------------------
0000          0    0     0x2345
0001          1    1     0x1234
0002          0    1     0xAD12
and so ...


To do it, I am using a CListCtrl in report view and it works ok, but
now I need to modify the SubItems.

How can I modify a subItem when the user double-clicks on it?

By modify I mean the user be able to edit the SubItem text in place. 
If it isn't possible, I think I must use a dialog.

thanks,

---
Hector Fabio Restrepo
Laboratoire de Systemes Logiques
Ecole Polytechnique Federal de Laussane - Suisse
e-mail: restrepo@lslsun.epfl.ch



murugesh@mail.cswl.com
Sunday, September 15, 1996

     Hai,
     
     There are two options 
     
     1. Its little bit difficult to achieve this through listcontrol. It is 
     easy to do by poping up a dialog to edit the content.
     
     2. Instead of  using the listview control u can use the grid control. 
     To edit the content u can create a edit box on the fly over the 
     particular cell or u can popup a dialog to edit the content.
     
     Regards
     Murugesh SS
     Murugesh@cswl.com
     
     
        


______________________________ Reply Separator _________________________________
Subject: ClistCtrl Question
Author:  mfc-l@netcom.com at internet
Date:    9/14/96 11:11 PM


Environment: VC++ 4.0, Windows NT 3.51
     
I am writing an application where one of the windows displays the 
information contained in a memory. The information on the window 
looks like :
     
Address       LB   HB    Data
----------------------------------
0000          0    0     0x2345
0001          1    1     0x1234
0002          0    1     0xAD12
and so ...
     
     
To do it, I am using a CListCtrl in report view and it works ok, but 
now I need to modify the SubItems.
     
How can I modify a subItem when the user double-clicks on it?
     
By modify I mean the user be able to edit the SubItem text in place. 
If it isn't possible, I think I must use a dialog.
     
thanks,
     
---
Hector Fabio Restrepo
Laboratoire de Systemes Logiques
Ecole Polytechnique Federal de Laussane - Suisse 
e-mail: restrepo@lslsun.epfl.ch




LeRoy Baxter -- lbaxter@transport.com
Saturday, September 14, 1996

I did what you want to do using a regular, owner-draw listbox
and instantiating an edit box for the fields (sub items).   When
the focus first moves to the listbox, you unhide the edit control,
fill it with the text of the first field and move it so it covers the
field.   As the user tabs to the next field, you save any edits, 
load the text for the next field, and move the edit control - etc.
you have to handle up arrows, down arrows, and tabbing
from the listbox.

Short of buying a custom grid control, this is about the only
way to accomplish what you are asking.
 

Hector Fabio RESTREPO[SMTP:restrepo@di.epfl.ch] wrote:
>Environment: VC++ 4.0, Windows NT 3.51
>
>I am writing an application where one of the windows displays the
>information contained in a memory. The information on the window
>looks like :
>
>Address       LB   HB    Data
>----------------------------------
>0000          0    0     0x2345
>0001          1    1     0x1234
>0002          0    1     0xAD12
>and so ...
>
>
>To do it, I am using a CListCtrl in report view and it works ok, but
>now I need to modify the SubItems.
>
>How can I modify a subItem when the user double-clicks on it?
>
>By modify I mean the user be able to edit the SubItem text in place. 
>If it isn't possible, I think I must use a dialog.
>
>thanks,
>
>---
>Hector Fabio Restrepo
>Laboratoire de Systemes Logiques
>Ecole Polytechnique Federal de Laussane - Suisse
>e-mail: restrepo@lslsun.epfl.ch
>





GoroKhM1 -- gorokhm1@SMTP.ATG-NET.COM
Monday, September 16, 1996

[Mini-digest: 4 responses]

     
That question was recently discussed. You can't edit directly a subitem. 
The only way is to create edit box and place it precisely on a place
where you want to change data. You have to care about List sizing, 
scrolling, etc.

Mark


______________________________ Reply Separator _________________________________
Subject: ClistCtrl Question
Author:  mfc-l@netcom.com at INTERNET
Date:    9/14/96 3:39 PM


Environment: VC++ 4.0, Windows NT 3.51
     
I am writing an application where one of the windows displays the 
information contained in a memory. The information on the window 
looks like :
     
Address       LB   HB    Data
----------------------------------
0000          0    0     0x2345
0001          1    1     0x1234
0002          0    1     0xAD12
and so ...
     
     
To do it, I am using a CListCtrl in report view and it works ok, but 
now I need to modify the SubItems.
     
How can I modify a subItem when the user double-clicks on it?
     
By modify I mean the user be able to edit the SubItem text in place. 
If it isn't possible, I think I must use a dialog.
     
thanks,
     
---
Hector Fabio Restrepo
Laboratoire de Systemes Logiques
Ecole Polytechnique Federal de Laussane - Suisse 
e-mail: restrepo@lslsun.epfl.ch

-----From: Sumit Chawla 

Environment: VC++ 4.0, Windows NT 3.51

Modifying a subitem is not really diificult but it ia a bit tedious.
Here's what I do (this may not be the best way to do it though):

1. Create an edit control as a member of CListCtrl derived class and
   set its font to match that of the list control. Do not show the
   edit control initially.

2. OnLButtonDblClk calculate the rect of the subitem and use this rect
   to display the edit control. Set the text of the edit control using
   the subitem text.

3. Use the EN_KILLFOUCUS notification from the edit control to  update
   the changed text.

Hope this helps

Sumit Chawla
schawla@csci.csc.com


-----From: Roger Onslow/Newcastle/Computer Systems Australia/AU

Hector,

Basic method would be as follows:

You can detect a click in the list control.
You then need to determine which column it is in
(need to loop thru columns and add up column widths and compare to x-coord of 
click)
Also need to determin which column it is in
(do hit test on copy of click point with x set to 1 so it is in label area, 
then can find item)
Determine the rect that corresponds to the row/column cell
Create an edit box and place it over the cell
Copy from sub-item in the cell to the edit control
Let user edit the edit control
Copy value from edit into sub-item in the cell

Alternative:
Put edit fields for the sub-items on your dialog/window
As you move thru the list control, copy the subitem values for the current row 
into the edit boxes
If the user changes an edit box, copy it into the sub-item for the current row.
Perhaps add a "Modify" button to the dialog/window to apply changes
Can also use this to provide for adding new values.

Yet another way:
Detect double click (or right click) on a row.
Pop-up a dialog that allows you to edit all values for the row
When dialgo returns IDOK, copy result back into the list control

Roger Onslow
-----From: Dave_Rabbers@Quinton-Eng.CCMAIL.CompuServe.COM

     
I assume you are using report mode.
The CListCtrl only supports in-place editing the left most column.  It is fairly
easy, but a bit involved, to in-place edit any column.

I'm giving you the following steps from memory, so if I've left anything out, I 
apologize.  It will probably be obvious to you when you do this.

First you have to capture the double-click mouse message.
Then determine which row and column was clicked.  There are methods on CListCtrl
to do this.
Next, determine the size of the item you wish to edit, or perhaps the size you 
wish to allow editing.  Also determine the upper left corner of the element you 
want to edit (take a look at the current top-most element number in your 
calculations).  This is the most involved step.
Construct your own edit box at this location, of the size you determine (make 
sure you allow for an edit box bigger than the text area, since edit boxes have 
borders).
Initialize the edit box with the current data item value (if desired) from the 
CListCtrl.
Capture the enter key stroke on the edit box.  I think you have to do this with 
a WM_KEYDOWN or WM_KEYUP.
Update the CListCtrl data item from the CEdit value.

A bit messy and involved.  Sure would be nice if MS did this for you.

Other alternatives:
Look at the grid control that ships with MFC in the component gallery.
Look at grid controls from other companies.  There are several that are more 
like a VB grid control, more like what you want.

But it can be done in VC++.



Norman C. Byers -- nbyers@intxxnet.com
Wednesday, September 18, 1996

Concerning in-place editing with a CListCtrl. Other than 
using a 3rd party spreadsheet or grid control you can use 
the CTreeCtrl to create a simple single or dual column list 
with in-place editing. I'm not altogether sure it is less 
work than overlaying the edit control as the CTreeCtrl 
carries its own burden of complexity.
-- 
II*




| Вернуться в корень Архива |