Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Selection and sel change notification bug
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Selection and sel change notification bug

 Post Reply Post Reply
Author
Message
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Topic: Selection and sel change notification bug
    Posted: 12 January 2009 at 10:28pm
Hi

Something weird happening with the selection / onselchange notification.

I've got a handler on the XTP_NM_REPORT_SELCHANGED message.

If you populate a report control, by default it selects a record for you (I hate this). So, whenever I populate my control, I also have to call

GetSelectedRows()->Clear(); // lame

If you sort the control by any column, it again chooses to select a row, however it does NOT send XTP_NM_REPORT_SELCHANGED, so my handler isn't getting hit.

This is with 12.1.0


Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 13 January 2009 at 12:52am
You have no selection now - you only have Focused Row!
Try such sample:

ON_NOTIFY(XTP_NM_REPORT_SELCHANGED, XTP_ID_REPORT_CONTROL, OnReportSelectionChanged)

ON_NOTIFY(XTP_NM_REPORT_PRESORTORDERCHANGED, XTP_ID_REPORT_CONTROL, OnReportPresort)

ON_NOTIFY(XTP_NM_REPORT_SORTORDERCHANGED, XTP_ID_REPORT_CONTROL, OnReportSort)

int CTaskListView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{
....

GetReportCtrl().GetSelectedRows()->Clear();

}
 
void CTaskListView::OnReportSelectionChanged(NMHDR* /*pNotifyStruct*/, LRESULT* /*result*/)

{

CXTPReportSelectedRows* pSelectedRows = GetReportCtrl().GetSelectedRows();

CFrameWnd* pFrame = (CFrameWnd* ) AfxGetMainWnd();

if (pFrame != NULL && pSelectedRows != NULL && pSelectedRows->GetCount() > 0)

{

CString s;

s.Format("Selected rows %d from %d",

pSelectedRows->GetCount(),

pSelectedRows->GetAt(0)->GetIndex());

pFrame->SetMessageText(s);

}

}

void CTaskListView::OnReportPresort(NMHDR* /*pNotifyStruct*/, LRESULT* /*result*/)

{

GetReportCtrl().GetSelectedRows()->Add(GetReportCtrl().GetFocusedRow());

}

void CTaskListView::OnReportSort(NMHDR* /*pNotifyStruct*/, LRESULT* /*result*/)

{

GetReportCtrl().GetSelectedRows()->Clear();

}

See status bar of Main Window - ReportSample - it reflect XTP_NM_REPORT_SELCHANGED handling

Back to Top
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2009 at 4:41pm
it's true, I get a focus rect around the first item when I clear the selected rows.

but I don't see how your example is going to help me.

I need to handle sel changes, and the existing code is doing that already. what I need to prevent is the control from automatically selecting a row when no-one clicked on any row. If I have to handle the sort order changed event, I'd need to then know whether someone had a row previously selected or not.

It's not sooo bad that it selects the row, but it is bad that it doesn't tell me the selection has changed - this is a bug. At one point there is no selected row, then there is a selected row, but no notification.

Personally I think it shouldn't select any rows unless a user clicks on a row, or a programmer adds the row to the selected rows container in code.
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2009 at 7:32pm
Essentially you should deal on app level with 3 events:

ON_NOTIFY(XTP_NM_REPORT_SELCHANGED, XTP_ID_REPORT_CONTROL, OnReportSelectionChanged)

ON_NOTIFY(XTP_NM_REPORT_FOCUS_CHANGING, XTP_ID_REPORT_CONTROL, OnReportFocusChanged)

ON_NOTIFY(XTP_NM_REPORT_LBUTTONDOWN, XTP_ID_REPORT_CONTROL, OnReportLbDown)

void CTaskListView::OnReportLbDown(NMHDR* /*pNotifyStruct*/, LRESULT* /*result*/)

{

m_bAllowSelect = TRUE;

}

void CTaskListView::OnReportFocusChanged(NMHDR* /*pNotifyStruct*/, LRESULT* result)

{

CXTPReportSelectedRows* pSelectedRows = GetReportCtrl().GetSelectedRows();

if (pSelectedRows)

pSelectedRows->Clear();

}

void CTaskListView::OnReportSelectionChanged(NMHDR* /*pNotifyStruct*/, LRESULT* /*result*/)

{

CXTPReportSelectedRows* pSelectedRows = GetReportCtrl().GetSelectedRows();

if (pSelectedRows)

{

if (!m_bAllowSelect)

pSelectedRows->Clear();

else

{

m_bAllowSelect = FALSE;

pSelectedRows->Add(GetReportCtrl().GetFocusedRow());

}

}

}

and flag
BOOL m_bAllowSelect;
which you should to be FALSE end the end of initialization  together with cleaning selection:
 

int CTaskListView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

........
m_bAllowSelect = FALSE;

GetReportCtrl().GetSelectedRows()->Clear();

}
 
Back to Top
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2009 at 10:32pm
ok I guess that would work...

or maybe the report control could be fixed?

I've got quite a few report controls I'm using that do this...
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2009 at 10:44pm
I know that it works - I tested it before sending to you. You should consider different situation with the way you react on mouse click - sometims such click means select a word in InPlace editor (normal behaviour of edit control), sometimes you allow to select subitem, sometimes - not.
Don't expect ReportControl to change existed behaviour - maximum I can do if will be enough client asking about such feature - introduce some binary or enumerated flag - mouse click VS keyboard navigation - select or not  (looks like 4 different cases - NO-NO, YES-NO and so on).
But not in release 13 for sure.
But usually such specific reaction implemented on app level - this is way control is sending notification and app can choose that to do...
 
Btw - as I explain you in very begining of our discussion - you use wrong term in this topic title as  this is NOT a BUG - this is proper reaction on specific action - Focus vs Selection.
Back to Top
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2009 at 11:45pm
My complaint is that the control selects a row when there was

a) no click on the row
b) no keyboard input (e.g no keyboard selection)

furthermore it selects said row without sending XTP_NM_REPORT_SELCHANGED

If going from 0 selected rows to 1 selected row is not a change in selection then I don't know what is.

So, I guess we disagree whether this is a bug or not, I remain unconvinced that it is not.

I'm not going to go through the dozens of places I use report control to add 3 handlers to "fix" this problem, instead I will more likely have to hack the report control source to have it simply not decide to randomly select rows all by itself.
Back to Top
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2009 at 11:54pm
p.s. I'm not trying to get it to behave differently between keyboard vs mouse user input.

I'm trying to get it to stop selecting the row by itself, with NO human input.
Back to Top
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2009 at 11:55pm
p.p.s (sorry) failing that if the report control must select a row of its own accord, it should notify this.
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 19 January 2009 at 12:11am
I can agree with last sentence - this is result of Populate function call. This function check IsSelectionEnabled() flag and if TRUE - make selection internally - without notification. If you call

wndReport.SelectionEnable(FALSE);

wndReport.Populate();

wndReport.SelectionEnable(TRUE);

you will have expected behaviour. After this point keyboard steps or mouse click will generate same effect - and will send notification to app. So you can have only one your own function

OnReportSelectionChanged for customization. If it what you want? If so - no need to have mode complicated model I propose you because my idea realized different reaction on keyboard and on mouse! (It have sense in some business model!)

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 19 January 2009 at 12:13am
P.S. Check - how many cases of Populate() calls you have - you need to modify all with same approach (3 lines instead of 1)
 
You can also get rid from Focus

wndReport.SelectionEnable(FALSE);

wndReport.Populate();

wndReport.ShowRowFocus(FALSE);

wndReport.SelectionEnable(TRUE);

and turn it back when you need using call:

wndReport.ShowRowFocus(TRUE);

Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 19 January 2009 at 9:42am
Hi,
 finally I implemented bool flag InitialSelectionEnable to control Populate function - you can call it ONCE and not auto-selection for Populate calls. It exposed to VB also
Back to Top
adrien View Drop Down
Senior Member
Senior Member


Joined: 30 April 2007
Location: New Zealand
Status: Offline
Points: 449
Post Options Post Options   Thanks (0) Thanks(0)   Quote adrien Quote  Post ReplyReply Direct Link To This Post Posted: 20 January 2009 at 4:50pm
excellent, thanks so much!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.