wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected Topic is solved
wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
Hi All,
I'm using single selection wxListCtrl. I found when I select a selected item again, it won't trigger wxEVT_LIST_ITEM_SELECTED event.
How can I get wxEVT_LIST_ITEM_SELECTED event from selected item? I really need this kind of behavior.
Thanks!
I'm using single selection wxListCtrl. I found when I select a selected item again, it won't trigger wxEVT_LIST_ITEM_SELECTED event.
How can I get wxEVT_LIST_ITEM_SELECTED event from selected item? I really need this kind of behavior.
Thanks!
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
I bind this event:
this->mylist->Bind(wxEVT_LEFT_UP, &MyList::OnClickListItem, this, this->mylist->GetId());
void MyList::OnClickListItem(wxMouseEvent& event) {
int eventx = this->mylist->ScreenToClient(wxGetMousePosition()).x;
int eventy = this->mylist->ScreenToClient(wxGetMousePosition()).y;
wxPoint mouse(eventx, eventy);
int flag = wxLIST_HITTEST_ONITEMLABEL;
long row = this->mylist->HitTest(mouse, flag);
if (row >= 0) {
//do action here...
}
}
It seems solve the problem. But why I only can get double click(left) mouse event in OnClickListItem?
this->mylist->Bind(wxEVT_LEFT_UP, &MyList::OnClickListItem, this, this->mylist->GetId());
void MyList::OnClickListItem(wxMouseEvent& event) {
int eventx = this->mylist->ScreenToClient(wxGetMousePosition()).x;
int eventy = this->mylist->ScreenToClient(wxGetMousePosition()).y;
wxPoint mouse(eventx, eventy);
int flag = wxLIST_HITTEST_ONITEMLABEL;
long row = this->mylist->HitTest(mouse, flag);
if (row >= 0) {
//do action here...
}
}
It seems solve the problem. But why I only can get double click(left) mouse event in OnClickListItem?
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
If I change wxEVT_LEFT_UP to wxEVT_LEFT_DOWN, then I could get left button single clicking mouse event.
But I got a new problem, no highlight on selected item is showing. If response wxEVT_LEFT_UP, the highlight is showing.
Anybody could help me out? Thanks!
But I got a new problem, no highlight on selected item is showing. If response wxEVT_LEFT_UP, the highlight is showing.
Anybody could help me out? Thanks!
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
even I set -- this->mylist->SetItemState(row, 1, wxLIST_STATE_SELECTED), it's still useless.
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
Oh, I got stupid, should be: this->mylist->SetItemState(row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED) to select an item.
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
The whole solve way is:
this->mylist->Bind(wxEVT_LEFT_DOWN, &MyList::OnClickListItem, this, this->mylist->GetId());
this->mylist->Bind(wxEVT_LEFT_DCLICK, &MyList::OnClickListItem, this, this->mylist->GetId());
void MyList::OnClickListItem(wxMouseEvent& event) {
int eventx = this->mylist->ScreenToClient(wxGetMousePosition()).x;
int eventy = this->mylist->ScreenToClient(wxGetMousePosition()).y;
wxPoint mouse(eventx, eventy);
int flag = wxLIST_HITTEST_ONITEMLABEL;
long row = this->mylist->HitTest(mouse, flag);
if (row >= 0) {
//do action here...
this->mylist->SetItemState(row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
}
}
this->mylist->Bind(wxEVT_LEFT_DOWN, &MyList::OnClickListItem, this, this->mylist->GetId());
this->mylist->Bind(wxEVT_LEFT_DCLICK, &MyList::OnClickListItem, this, this->mylist->GetId());
void MyList::OnClickListItem(wxMouseEvent& event) {
int eventx = this->mylist->ScreenToClient(wxGetMousePosition()).x;
int eventy = this->mylist->ScreenToClient(wxGetMousePosition()).y;
wxPoint mouse(eventx, eventy);
int flag = wxLIST_HITTEST_ONITEMLABEL;
long row = this->mylist->HitTest(mouse, flag);
if (row >= 0) {
//do action here...
this->mylist->SetItemState(row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
}
}
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
Code: Select all
int eventx = this->mylist->ScreenToClient(wxGetMousePosition()).x;
int eventy = this->mylist->ScreenToClient(wxGetMousePosition()).y;
wxPoint mouse(eventx, eventy);
Call event.Skip() in the mouse event handler, so that the default processing can take place. Then you don't have to do the selection yourself.
Use the source, Luke!
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
Thanks doublemax, you always give us final professional answers!
I'd like ask you another question. If the listctrl is under Extended mode, how can I know the shift or ctrl key is pressing down when select item in list?
I'd like ask you another question. If the listctrl is under Extended mode, how can I know the shift or ctrl key is pressing down when select item in list?
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
Code: Select all
event.ShiftDown()
If this does not work with a wxMouseEvent (although it should), use wxGetKeyState():
https://docs.wxwidgets.org/trunk/group_ ... 41b71ce84f
Use the source, Luke!
Re: wxEVT_LIST_ITEM_SELECTED could not be triggered again if the item has been selected
event.ShiftDown() and event.ControlDown() are working. Thanks!doublemax wrote:https://docs.wxwidgets.org/trunk/classw ... state.htmlCode: Select all
event.ShiftDown()
If this does not work with a wxMouseEvent (although it should), use wxGetKeyState():
https://docs.wxwidgets.org/trunk/group_ ... 41b71ce84f