How to prevent item changed in a CListCtrl?

I use MFC Visual C++ 4.2.

I have a CListCtrl in a Detailed View.
Below the CListCtrl there are a few CEdits to display the value of each 
column.
So it's kind of the data form.

I need to do like this:
If users has changed one of the CEdits BUT they haven't save the data and 
they want to change the selected item of the CListCtrl to other item, a 
confirmation message will appear to ask if the data they have been changed to 
be saved or not.

There are 3 options:
Yes: the data change is saved and the current focus is on the item user 
desired.
No  : the data change is NOT saved and the current focus is on the item user 
desired.
Cancel: the data change is NOT saved and the current focus is STILL on the 
OLD item which is FIRST focused.

I have tried the OnItemChange or OnItemChanging and I have the No option 
worked. 

If I test Yes / Cancel, the messagebox will show 2-3 times then it return. 

Thank you very much.

Here is my code: 
void CToiawaseDlg::OnItemchangedLstData(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int iIndex = pNMListView->iItem;
	if( iIndex != -1 ){
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
		if( m_bDetailChanged && !m_bUpdateBtnClicked ){
			int iDlgResult = MessageBox( "Save data?", "Confirm", MB_YESNOCANCEL | 
MB_ICONQUESTION);
			if( iDlgResult == IDYES )
				AfxMessageBox( "Yes" ); 
			else if( iDlgResult == IDCANCEL ){
				m_lst_data.SetItemState( iIndex, LVIS_SELECTED, LVIS_SELECTED );
				m_lst_data.EnsureVisible( iIndex, FALSE );
				*pResult = 1;
			}
			m_bDetailChanged = FALSE;
		}
    }
}
0
landon (165)
9/11/2008 8:20:01 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
1149 Views

Similar Articles

[PageSpeed] 52

You would only want to show the message box if the old state of the item 
being passed into LVN_ITEMCHANGED has LVIS_SELECTED set.

something like this
void CToiawaseDlg::OnItemchangedLstData(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
    //if an item is being unselected
    if ((pNMLV->uOldState & LVN_SELECTED) == LVN_SELECTED && 
bItemWasEditied)
    {
        if (MessageBox(....)  == IDYES)
        {
            //save item
        }
    }
}

AliR.

"Landon" <Landon@discussions.microsoft.com> wrote in message 
news:0F687943-0B0E-4237-BE93-964D6C4884A3@microsoft.com...
>I use MFC Visual C++ 4.2.
>
> I have a CListCtrl in a Detailed View.
> Below the CListCtrl there are a few CEdits to display the value of each
> column.
> So it's kind of the data form.
>
> I need to do like this:
> If users has changed one of the CEdits BUT they haven't save the data and
> they want to change the selected item of the CListCtrl to other item, a
> confirmation message will appear to ask if the data they have been changed 
> to
> be saved or not.
>
> There are 3 options:
> Yes: the data change is saved and the current focus is on the item user
> desired.
> No  : the data change is NOT saved and the current focus is on the item 
> user
> desired.
> Cancel: the data change is NOT saved and the current focus is STILL on the
> OLD item which is FIRST focused.
>
> I have tried the OnItemChange or OnItemChanging and I have the No option
> worked.
>
> If I test Yes / Cancel, the messagebox will show 2-3 times then it return.
>
> Thank you very much.
>
> Here is my code:
> void CToiawaseDlg::OnItemchangedLstData(NMHDR* pNMHDR, LRESULT* pResult)
> {
> int iIndex = pNMListView->iItem;
> if( iIndex != -1 ){
> NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
> if( m_bDetailChanged && !m_bUpdateBtnClicked ){
> int iDlgResult = MessageBox( "Save data?", "Confirm", MB_YESNOCANCEL |
> MB_ICONQUESTION);
> if( iDlgResult == IDYES )
> AfxMessageBox( "Yes" );
> else if( iDlgResult == IDCANCEL ){
> m_lst_data.SetItemState( iIndex, LVIS_SELECTED, LVIS_SELECTED );
> m_lst_data.EnsureVisible( iIndex, FALSE );
> *pResult = 1;
> }
> m_bDetailChanged = FALSE;
> }
>    }
> } 


0
AliR3470 (3236)
9/11/2008 4:46:56 PM
How to handle if user chose Cancel option? I have been able to handle Yes and 
No but the problem now is Cancel. I need that if user has made changes in one 
of the CEdit, and then they change the item selection, if they choose Cancel, 
the focus / selection MUST NOT moved from the current line or in other word, 
nothing happened.

How to do that? 

I have tried to handle the Yes option only but when I tested it, the 
selection still moved to the new item user selected.

Thank you.
0
landon (165)
9/12/2008 12:31:00 AM
I was about to suggest using LVN_ITEMCHANGING message instead, that lets you 
cancel a change by returning non-zero. But I tested this and it has 
undesirable results.
Here is my test code:

void CListCtrlDlg::OnLvnItemchangingList1(NMHDR *pNMHDR, LRESULT *pResult)
{
   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

   if((pNMLV->uNewState != pNMLV->uOldState) && ((pNMLV->uOldState & 
LVIS_SELECTED) == LVIS_SELECTED))
   {
      int ret = MessageBox("Do you want to 
Save?","Save",MB_YESNOCANCEL|MB_ICONQUESTION);
      if (ret == IDCANCEL)
      {
         *pResult = 1;
         return;
      }
      else if (ret == IDYES)
      {
         //Save();
      }
   }
   *pResult = 0;
}

What I saw the if Yes or No was clicked then everything works as expected. 
If Cancel is clicked then the same message with the same exact item with the 
same exact state gets posted 1 or more times, which results in the dialogbox 
coming up again, and once the repeated messages stop both the old item and 
new item are selected, as you would have to cancel the selection of the new 
item also.  I wasn't able to figure out a solution for this.

I can only give you two suggestions, let me edit the item within the list 
control using Label Edit.  Or you can simply have button that says modify, 
and once that is clicked enable your edit controls, and disable your 
listcontrol so that they can't change selections until they have saved the 
info.

Sorry I couldn't be more help on this.
AliR.





"Landon" <Landon@discussions.microsoft.com> wrote in message 
news:8E22F79C-9548-46FF-92BD-BEB3EA15A66B@microsoft.com...
> How to handle if user chose Cancel option? I have been able to handle Yes 
> and
> No but the problem now is Cancel. I need that if user has made changes in 
> one
> of the CEdit, and then they change the item selection, if they choose 
> Cancel,
> the focus / selection MUST NOT moved from the current line or in other 
> word,
> nothing happened.
>
> How to do that?
>
> I have tried to handle the Yes option only but when I tested it, the
> selection still moved to the new item user selected.
>
> Thank you. 


0
AliR3470 (3236)
9/12/2008 3:27:22 PM
Reply:

Similar Artilces:

Can I change the calendar year beginning date?
Our fiscal year runs July 1 thru June 30 of each year. I need to track attendance, gas cards, etc for monthly reports. I have a HUGE table with a gazillion queries and reports for each one. I need one report to reflect quarterly output for our fiscal year as stated above. Can I make this report do that? Thank you! Create a query to use as the source for your report. In query design, type this into the Field row: FinYear: DateAdd("m", -6, [InvoiceDate]) replacing InvoiceDate with the name of your date field. This yields 2007 for all dates in the 2007/2008 financial year...

change horizontal header position in excel
Anyone know how to change the horizontal position of the HEADER or FOOTER in EXCEL???? I would greatly appreciate any help. Thank you for your time. pico Wrote: > Anyone know how to change the horizontal position of the HEADER o > FOOTER in > EXCEL???? I would greatly appreciate any help. Thank you for your time. Pico, Can't you go into View/Header-Footer and use the "Left-Center-Right" catagories? You could use spaces in front of your data to move back an forth. Dav -- Piranh ----------------------------------------------------------------------- Piranha's Profi...

Discount all items in a department?
Is it possible to discount all the items in a department (or other specified group) in one go? E.g. I want to discount all our 'media' department by 10% Help. El Presidente, SO Manager --> Wizards menu --> Inventory Wizard --> Task 110 Change Item Price --> Press Next --> Choose the Department --> Press Next, this is where we need to figure out if you are doing a permanent mark down or a sale for a specific period of time. For a Permanent Mark Down: Price change method = Discount from Regular price Percentage = 10% Price to be changed = Regular Sale for a spe...

Why is Excel changing the last 2 digits of a 17 digit num to 00.
When I enter a 17 digit number in a cell in Excel, the last 2 digits turn to 00 when I leave the cell. Format - Cell does not have a setting to stop this 'feature'. How do I make Excel recongize the large number? On Thu, 28 Jul 2005 19:09:01 -0700, "Allie" <Allie@discussions.microsoft.com> wrote: >When I enter a 17 digit number in a cell in Excel, the last 2 digits turn to >00 when I leave the cell. Format - Cell does not have a setting to stop this >'feature'. Excel Specifications and Limits: Calculation specifications Feature Maximu...

Detect page change in PropertySheet?
Hi, I have a property sheet that is the parent of several property pages. If the user clicks a tab to change to another page, is there a way I can detect this (and possibly prevent the change) in the PropertySheet dialog? Does windows/MFC send any kind of message to the PropertySheet dialog? I looked at all of the over-rides and WM_ message, but cannot see anything. Thanks! Not directly. You can catch that in the CPropertyPage and relay the message to the CPropertySheet. (I know you are asking, why doesn't the CPropertySheet get the notificatio first? who knows!) AliR. "...

Changing e-mail address
dI´m trying to change mail-address in AD-Users and computer. From "nnnn@xxx.xx" to "nnnn@yyy.xx", but it won't work. On the tab "e-mail Addresses" i try to set "nnnn@yyy.xx" as Primary, but it don't stay that way. If I open directly and check it seems right, but close and do one more client, the first has change back to "nnnn@xxx.xx". What am I doing wrong ???????? You will need to uncheck the checkbox "Automatically update e-mail addresses based on recipient policy" for the change to stay. Also make sure that you ...

... I want to change a chart type ...
I have a "Line - Column" chart in my spreadsheet. My Bars represent the month which is in a Linked Cell. The Value of the Bars is a Dollar amount from a Linked Cell. The Line represents a Target Dollar Value. I would like to add a second line that would represent a count from a linked range of cells. Can I edit my existing chart, or do I have to create a new one? Could you give me a few pointers? Darrell Select and drag the new column onto the chart. In the resulting dialog box, ensure you specify 'new series'. Once XL finishes adding the series, if it is not the...

Changing fonts in msgbox
If i create a msgbox with a prompt, can i change or modify the font of the text in the msgbox ?? Ditto Inputbox.... thanks! ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ You can't change the font used in a MsgBox. This limitation is one of the prices you pay for the simplicity of a MsgBox. If you need to change the font, you need to create a UserForm and display that form instead of using a MsgBox. -- Cordially, Chip Pearson Microsoft MVP - Excel www.cpears...

Change of field separator
When I open CSV files in Excel all data is put in one column. Can anyone tell me, where I change my set up, so I get another field separator? Please be specific, because my Excel is a Danish version, and sometimes I have a hard time following the English instructions. Thanks! Jane Hi you specify this in the Windows regional settings. Another idea: - rename your *.csv file to a *.txt file - now open it with excel. The Import wizard should appear and should allow you to specify a different delimiter "Janepige" wrote: > When I open CSV files in Excel all data is put in one co...

Paper settings change for specific printer
I just installed access 2007 and my application uses reports to print labels. Specifically a Dymo turbo 400 and 30252 address labels. when i was using acess 2003 i specified to use a specific printer and everything was great. and when i copied updated FrontEnds to my networked computers every thing transfered and the labels printed fine however with 07 the "Specifc printer" has a different page size.. i fixed all the reports on my master FE but the changes didnt stay when i copied FE to other computers and im not sure where to go. i installed all the printers from the s...

Prevent users from saving music and pictures to their hard drives without folder redirection?
Hi there. I'm wondering if there is a way via GPO or anything else to prevent users from saving music and pictures to their local hard drives without using any type of profile or folder redirection. Thanks. ...

Copy Matrix Items
I am afraid I know the answer to this already but here goes- I have a prospective shoe store customer who receives as many as 500 pairs of shoes in a lot. Most of the time 50% or more of these shoes have not been stocked before and they don't know what the shoes will be until they get the lot. Because of the nature of shoes they need the ability to quickly enter in the assorted sizes and colors in a run of Men's, Women's, Children's etc. While the New Item Wizard for a Matrix Item works well the customer would like to not have to enter in the size runs each time since they a...

How do I change numbers to negative without re-typing?
I have a large range of data that needs to be changed to negative numbers, Can I do this in Excel? ...

How to Change Outgoing port in Exchange 2003
I am running Exchange 2003 on a SBS 2003 server and using the POP3 connector to get the e-mail from my account and also send the email out throught the SMTP server. Starting last Friday the outgoing mail is not being sent. Earthlink tells me that they are now using port 587 for the outgoing mail. How do I change the outgoing mail SMTP port? Thanks -- Don Holden -- Don Holden On Mon, 26 Jun 2006 09:07:02 -0700, Don Holden <DonHolden@discussions.microsoft.com> wrote: >I am running Exchange 2003 on a SBS 2003 server and using the POP3 connector >to get the e-mail from my...

grayscale autoshape changes to color when converting to PDF
When converting from Microsoft Publisher 2007 to Adobe Acrobat 8.0 PDF, the autoshape picture that we changed to grayscale changes back to color when reviewing the created PDF. Are you setting Acrobat to print in black and white? Select the PDF printer, properties, paper/quality tab. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "CDJ" <CDJ@discussions.microsoft.com> wrote in message news:6BE9EE01-97DB-4AB6-BD9C-25E27E0BB68D@microsoft.com... > When converting from Microsoft Publisher 2007 to Adobe Acrobat 8.0 P...

Highlight color for selected items
How can I find out what color is used for highlighting selected items (for example in Windows Explorer)on a users computer? Normally it is a blue color, but a user can change that. "Urban Olars" <anonymous@discussions.microsoft.com> wrote in message news:071c01c3c941$3db2c890$a401280a@phx.gbl... > How can I find out what color is used for highlighting > selected items (for example in Windows Explorer)on a users > computer? > Normally it is a blue color, but a user can change that. See if it's GetSysColor/COLOR_HIGHLIGHT. -- Jeff Partch [VC++ MVP] Take a ...

"Can't copy the items. You don't have permission ..."
I use OL 2003, latest service pack,etc. My PST file is about 1.2 GB and is Unicode-compatible. Lately Outlook shuts down suddenly without warning, and I have left checked the box to restart Outlook automatically. This is a big annoyance. However, in the last 2-3 days, I'm seeing a new kind of problem. I can't delete or move messages from mail folders. I get the message that is in the subject line, and the balance of this message is: ... to create an entry in this folder. Right-click the folder and then click Properties to check your permissions for the folder. See the folder o...

Outlook changing PDF extention to PDF=
I have a client that uses Outlook 2000 for e-mail. About a week ago, she started complaining that everyone that she sent PDFs (Ex. Document.pdf) that they were receiving PDF= (Ex. Docuement.pdf=). This is only happening with PDF files, not word documents or anything else. I have tried to change the outgoing mail server, but that made no difference. Is there something in Outlook that can be causing this? is she using RTF formatted messages? Antivirus or antispam scanners on outgoing email? -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2...

Preventing changes in the Options
Hello, Is there a way in Excel to prevent users from making any changes in the Options (ie protect or disable the Options Dialog box). Thanks in advance, brgds, Chantal ...

How to change the FROM field in email campaign activity?
How to change the FROM field in email campaign activity? I would like to create an email campaign activity and change the TO field of the email to be abother name instead of mine I would also like to add attachments I can't find a way to do this Any help is very much appreciated Thank you Stella Hi Stella, There are many ways to send marketing emails from CRM: Quick Campaigns Quick Campaigns with mail merge using Microsoft Word E-mail Campaign Activities E-mail Campaign Activities with mail merge using Microsoft Word Direct e-mail using templates Send a workflow e-mail Integrate...

Need Help With GP Item Pricing
GP ITEM PRICING I need to use “Bucket Pricing” for items in GP. For example below is the pricing schedule that I need to use. First 20 …………….$ 1.75 Next 280 ……………… 1.36 Next 700 ……………… 1.23 Next 2,000 ……………… 1.09 Over 3,000 ……………… .82 So if I had a Qty. of 350 it would be as follows 20 * 1.75 = 35 280 * 1.36 = 380.80 50 * 1.23 = 61.50 Total : $477.30 In GP I can only set it up to do a “Quantity Range” in the Item Price List Maintenance window. Problem is if I set it up that way and enter a quantity of 350 it will default to the $1.23 ...

font change when editing
I have this I can place on the sheet module to change font when editing. Is there a way to put this into a macro so I can enter this into the sheet automatically each time I am emailed a new version of the workbook? Thanks. Private Sub Worksheet_Change(ByVal Target As Range) Target.Cells.Interior.ColorIndex = 4 End Sub ...

deleted items #7
Does anyone know what and how I can view and/or delete the 1129 items my Outlook says I have in my deleted items folder. 1 says unread. Thanks If can see the Deleted Items folder in the folder list, right-clicking on it reveals "Empty Deleted Items folder" If you can't see the folder list, it's under the 'Go' menu in Outlook 2003, and under the 'View' menu in earlier versions You can also empty the Deleted Items folder automatically every time you close Outlook. Tools menu > Options > 'Other' tab. Choose the 'Empty the Deleted Items f...

how do I format cells to change date and time to just date
I want to format a column that contains date and time and I want it to show just the date and not the time. Going into format and clicking on the date and changing doesnt work. Probably the cells aren't really dates, but text. You can check with the ISTEXT() function. If they are text, formatting doesn't have any effect. -- Kind regards, Niek Otten Microsoft MVP - Excel "bondam" <bondam@discussions.microsoft.com> wrote in message news:F4D61EC1-30E2-4723-89E1-F47B545818EE@microsoft.com... >I want to format a column that contains date and time and I want it t...

Can't change Passport
Trying to change Passport in MS Money 2005 Premium. Password Manager tells me to turn off remote access. Don't have option "Access your Money data on the Web" in Money Online Services. What should I do? Can anyone help? Thanks in advance... Nickolay In microsoft.public.money, sitkarev@gmail.com wrote: >Trying to change Passport in MS Money 2005 Premium. > >Password Manager tells me to turn off remote access. > >Don't have option "Access your Money data on the Web" in Money Online >Services. How about under Tools->Settings ? Thanks Cal...