Crashed from DataViewCtrl.SetSelections (6.3 KB)
Hi all,
I have two DataViewCtrl work fine with PyDataViewModel. (in wxpython 4.0.6)
What I want to do is moving some items from one control to another and then select them.
As the codes below, however, the call of self.dvc2.SetSelections(to_select) always make my program crashed.
Is it correct to use DataViewItemArray like this way? Any help would be much appreciated.

    def on_btn_auto_classify(self, event):
        mod1 = self.mod1
        mod2 = self.mod2
        to_select = dv.DataViewItemArray()
        undecided_grp =['undecided']
        for obj in list(undecided_grp.children):
            rand_grp =[f'group{random.randint(1, 3)}']
        #self.dvc2.SetSelections(to_select) # crashed

The problem is your implementation of GetParent of the Model class. It should return like

return self.ObjectToItem(group)

instead of

return self.ObjectToItem(obj)


Thanks ckkart,
You are right, the crashed problem is solved with the updated code: (6.3 KB)
However, another problem arises, the result of selection seems to be a mess.
I suspect if it is safe to call the function ObjectToItem() in my button handler, because the description in document seems to create ‘new’ DataViewItem:

ObjectToItem : Create a DataViewItem for the object, and remember the ID-.obj mapping.

But i cannot figure out other way to retrieve these DataViewItems and pass them to SetSelections().

It works fine here. Are you sure you haven’t changed anything else?

Screen Shot 2020-05-27 at 09.08.10

Yes, i used the code i uploaded above without any change (in win10, wxpython 4.0.6, python 3.6.4)
I ran it many times to see the results. Although the selection is correct once or twice, most times it give me the wrong outcome.

I observed several improvements/bug fixes with wxpython4.1 compared to 4.0 which are basically due to fixes in wxwidgets. Have you tried 4.1?

Hi ckkart,
It is so nice to hear about that.
I tested it today, and it works perfectly only after updating to wxpython 4.1.0.
All problems have been solved, I really appreciate your kindly effort and notice.