Quantcast

Getting row / col of selected cell in ListCtrl ?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting row / col of selected cell in ListCtrl ?

Stef Mientki-2
hello,

I've a ListCtrl in reportmode,
and I want  to detect when  the  user selects a  cell.
I got the select cell event working,
and now I need to know which row and column was selected.

Also a general question, where can I find what the procedures /
properties a certain event has ?
I find this a very intriguing question, because my IDE ( and probably
all IDEs),
can't give a list of the procedures. So for me it's just trial and error ;-)

here the code I've so far:

 # in on init of the form, the event is bound to OnItemSelect
    panel.Bind ( wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelect, self.List )

# in OnItem
    def OnItemSelect ( self, event):
        item = event.GetItem()
        print item.GetText()                      # prints text of
active row, column 0  ???

        # below doesn't work
        print self.List.GetItemPosition ( item )
        print self.List.GetItemText(item)

thanks,
Stef Mientki


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting row / col of selected cell in ListCtrl ?

Phillip Stevens
Hi Stef,

Try adding the following to your OnItemSelect()

        SelectedRow = event.GetRow()
        SelectedCol = event.GetCol()

---Phil



Sunday, August 5, 2007, 1:19:10 PM, you wrote:

> hello,

> I've a ListCtrl in reportmode,
> and I want  to detect when  the  user selects a  cell.
> I got the select cell event working,
> and now I need to know which row and column was selected.

> Also a general question, where can I find what the procedures /
> properties a certain event has ?
> I find this a very intriguing question, because my IDE ( and probably
> all IDEs),
> can't give a list of the procedures. So for me it's just trial and error ;-)

> here the code I've so far:

>  # in on init of the form, the event is bound to OnItemSelect
>     panel.Bind ( wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelect, self.List )

> # in OnItem
>     def OnItemSelect ( self, event):
>         item = event.GetItem()
>         print item.GetText()                      # prints text of
> active row, column 0  ???

>         # below doesn't work
>         print self.List.GetItemPosition ( item )
>         print self.List.GetItemText(item)

> thanks,
> Stef Mientki

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail:
> [hidden email]



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting row / col of selected cell in ListCtrl ?

Stef Mientki-2
thanks Phil,

trial and error ?
sorry it doesn't work:
  "AttributeError: 'ListEvent' object has no attribute 'GetCol' "

but you pointed me to the complete (well almost) solution ( I had seen
somewhere before):
  print dir (event )

which give me the answer:

['Allow', 'CacheFrom', 'CacheTo', 'Checked', 'ClassName', 'ClientData',
'ClientObject', 'Clone', 'Column', 'Data', 'Destroy', 'EventObject',
'EventType', 'ExtraLong', 'GetCacheFrom', 'GetCacheTo', 'GetClassName',
'GetClientData', 'GetClientObject', 'GetCode', 'GetColumn', 'GetData',
'GetEventObject', 'GetEventType', 'GetExtraLong', 'GetId', 'GetImage',
'GetIndex', 'GetInt', 'GetItem', 'GetKeyCode', 'GetLabel', 'GetMask',
'GetPoint', 'GetPosition', 'GetSelection', 'GetSkipped', 'GetString',
'GetText', 'GetTimestamp', 'Id', 'Image', 'Index', 'Int', 'IsAllowed',
'IsChecked', 'IsCommandEvent', 'IsEditCancelled', 'IsSameAs',
'IsSelection', 'Item', 'KeyCode', 'Label', 'Mask', 'Point',
'ResumePropagation', 'Selection', 'SetClientData', 'SetClientObject',
'SetEditCanceled', 'SetEventObject', 'SetEventType', 'SetExtraLong',
'SetId', 'SetInt', 'SetString', 'SetTimestamp', 'ShouldPropagate',
'Skip', 'Skipped', 'StopPropagation', 'String', 'Text', 'Timestamp',
'Veto', '__class__', '__del__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__swig_destroy__', '__weakref__', 'm_code', 'm_col', 'm_item',
'm_itemIndex', 'm_oldItemIndex', 'm_pointDrag', 'this', 'thisown']
(240, 248, 255, 255)

Now just one problem
   event. GetColumn()  always retuns 0
for now that's no problem,
but I've other applications where it matters.
Is this because there is always a row selected ?
Can I disable rowselect (couldn't find any setting for this)

cheers,
Stef Mientki

Phillip Stevens wrote:

> Hi Stef,
>
> Try adding the following to your OnItemSelect()
>
>         SelectedRow = event.GetRow()
>         SelectedCol = event.GetCol()
>
> ---Phil
>
>
>
> Sunday, August 5, 2007, 1:19:10 PM, you wrote:
>
>  
>> hello,
>>    
>
>  
>> I've a ListCtrl in reportmode,
>> and I want  to detect when  the  user selects a  cell.
>> I got the select cell event working,
>> and now I need to know which row and column was selected.
>>    
>
>  
>> Also a general question, where can I find what the procedures /
>> properties a certain event has ?
>> I find this a very intriguing question, because my IDE ( and probably
>> all IDEs),
>> can't give a list of the procedures. So for me it's just trial and error ;-)
>>    
>
>  
>> here the code I've so far:
>>    
>
>  
>>  # in on init of the form, the event is bound to OnItemSelect
>>     panel.Bind ( wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelect, self.List )
>>    
>
>  
>> # in OnItem
>>     def OnItemSelect ( self, event):
>>         item = event.GetItem()
>>         print item.GetText()                      # prints text of
>> active row, column 0  ???
>>    
>
>  
>>         # below doesn't work
>>         print self.List.GetItemPosition ( item )
>>         print self.List.GetItemText(item)
>>    
>
>  
>> thanks,
>> Stef Mientki
>>    
>
>  
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail:
>> [hidden email]
>>    
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>  


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re[2]: Getting row / col of selected cell in ListCtrl ?

Phillip Stevens
Hi Stef,

Sorry,  when you said "cell", "row",  and "col",  I thought you were dealing
with a grid control.  Re-Reading your post I now see it was a ListCtrl.

The best place I have found to find the methods and properties classes
have is:
http://wxpython.org/docs/api/wx-module.html
Or for The List control class:
http://wxpython.org/docs/api/wx.ListCtrl-class.html

---Phil

Sunday, August 5, 2007, 2:08:32 PM, you wrote:

> thanks Phil,

> trial and error ?
> sorry it doesn't work:
>   "AttributeError: 'ListEvent' object has no attribute 'GetCol' "

> but you pointed me to the complete (well almost) solution ( I had seen
> somewhere before):
>   print dir (event )

> which give me the answer:

> ['Allow', 'CacheFrom', 'CacheTo', 'Checked', 'ClassName', 'ClientData',
> 'ClientObject', 'Clone', 'Column', 'Data', 'Destroy', 'EventObject',
> 'EventType', 'ExtraLong', 'GetCacheFrom', 'GetCacheTo', 'GetClassName',
> 'GetClientData', 'GetClientObject', 'GetCode', 'GetColumn', 'GetData',
> 'GetEventObject', 'GetEventType', 'GetExtraLong', 'GetId', 'GetImage',
> 'GetIndex', 'GetInt', 'GetItem', 'GetKeyCode', 'GetLabel', 'GetMask',
> 'GetPoint', 'GetPosition', 'GetSelection', 'GetSkipped', 'GetString',
> 'GetText', 'GetTimestamp', 'Id', 'Image', 'Index', 'Int', 'IsAllowed',
> 'IsChecked', 'IsCommandEvent', 'IsEditCancelled', 'IsSameAs',
> 'IsSelection', 'Item', 'KeyCode', 'Label', 'Mask', 'Point',
> 'ResumePropagation', 'Selection', 'SetClientData', 'SetClientObject',
> 'SetEditCanceled', 'SetEventObject', 'SetEventType', 'SetExtraLong',
> 'SetId', 'SetInt', 'SetString', 'SetTimestamp', 'ShouldPropagate',
> 'Skip', 'Skipped', 'StopPropagation', 'String', 'Text', 'Timestamp',
> 'Veto', '__class__', '__del__', '__delattr__', '__dict__', '__doc__',
> '__getattribute__', '__hash__', '__init__', '__module__', '__new__',
> '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
> '__swig_destroy__', '__weakref__', 'm_code', 'm_col', 'm_item',
> 'm_itemIndex', 'm_oldItemIndex', 'm_pointDrag', 'this', 'thisown']
> (240, 248, 255, 255)

> Now just one problem
>    event. GetColumn()  always retuns 0
> for now that's no problem,
> but I've other applications where it matters.
> Is this because there is always a row selected ?
> Can I disable rowselect (couldn't find any setting for this)

> cheers,
> Stef Mientki

> Phillip Stevens wrote:
>> Hi Stef,
>>
>> Try adding the following to your OnItemSelect()
>>
>>         SelectedRow = event.GetRow()
>>         SelectedCol = event.GetCol()
>>
>> ---Phil
>>
>>
>>
>> Sunday, August 5, 2007, 1:19:10 PM, you wrote:
>>
>>  
>>> hello,
>>>    
>>
>>  
>>> I've a ListCtrl in reportmode,
>>> and I want  to detect when  the  user selects a  cell.
>>> I got the select cell event working,
>>> and now I need to know which row and column was selected.
>>>    
>>
>>  
>>> Also a general question, where can I find what the procedures /
>>> properties a certain event has ?
>>> I find this a very intriguing question, because my IDE ( and probably
>>> all IDEs),
>>> can't give a list of the procedures. So for me it's just trial and error ;-)
>>>    
>>
>>  
>>> here the code I've so far:
>>>    
>>
>>  
>>>  # in on init of the form, the event is bound to OnItemSelect
>>>     panel.Bind ( wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelect, self.List )
>>>    
>>
>>  
>>> # in OnItem
>>>     def OnItemSelect ( self, event):
>>>         item = event.GetItem()
>>>         print item.GetText()                      # prints text of
>>> active row, column 0  ???
>>>    
>>
>>  
>>>         # below doesn't work
>>>         print self.List.GetItemPosition ( item )
>>>         print self.List.GetItemText(item)
>>>    
>>
>>  
>>> thanks,
>>> Stef Mientki
>>>    
>>
>>  
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail:
>>> [hidden email]
>>>    
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>>  

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail:
> [hidden email]



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting row / col of selected cell in ListCtrl ?

Christian K.
In reply to this post by Stef Mientki-2
Stef Mientki wrote:
> hello,
>
> I've a ListCtrl in reportmode,
> and I want  to detect when  the  user selects a  cell.
> I got the select cell event working,
> and now I need to know which row and column was selected.
>
> Also a general question, where can I find what the procedures /
> properties a certain event has ?


How about the docs?

http://wxwidgets.org/manuals/stable/wx_wxlistevent.html#wxlistevent

Christian



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Re: Getting row / col of selected cell in ListCtrl ?

Stef Mientki-2


Christian K wrote:

> Stef Mientki wrote:
>  
>> hello,
>>
>> I've a ListCtrl in reportmode,
>> and I want  to detect when  the  user selects a  cell.
>> I got the select cell event working,
>> and now I need to know which row and column was selected.
>>
>> Also a general question, where can I find what the procedures /
>> properties a certain event has ?
>>    
>
>
> How about the docs?
>
> http://wxwidgets.org/manuals/stable/wx_wxlistevent.html#wxlistevent
>
> Christian
>
>  
thanks Christian,
that's a very valuable piece of information,
looks much better than what I used before
  http://wxpython.org/docs/api/frames.html

cheers,
Stef Mientki



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting row / col of selected cell in ListCtrl ?

Robin Dunn
In reply to this post by Stef Mientki-2
Stef Mientki wrote:
> hello,
>
> I've a ListCtrl in reportmode,
> and I want  to detect when  the  user selects a  cell.
> I got the select cell event working,
> and now I need to know which row and column was selected.

A listctrl only has "items," which in report mode are viewed as rows.
It doesn't have real good support for dealing with the columns, except
for column headers, so you have to do a bit of work yourself to be able
to find which column the mouse was over when a item (row) is clicked.
Basically you need to catch the mouse events (and Skip it so the native
handler will still be run) and then calculate which column it is over by
looking at all of the column widths.  There is some code in
wx.lib.mixins.listctrl.TextEditMixin that shows how to do this.


--
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting row / col of selected cell in ListCtrl ?

Colin J. Williams
In reply to this post by Stef Mientki-2
Stef Mientki wrote:
> hello,
> ...
> Also a general question, where can I find what the procedures /
> properties a certain event has ?
> I find this a very intriguing question, because my IDE ( and probably
> all IDEs),
> can't give a list of the procedures. So for me it's just trial and error
> ;-)
PyScripter gives help here.

Colin W.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Re: Getting row / col of selected cell in ListCtrl ?

Mike Rooney
Colin J. Williams wrote:

> Stef Mientki wrote:
>> hello,
>> ...
>> Also a general question, where can I find what the procedures /
>> properties a certain event has ?
>> I find this a very intriguing question, because my IDE ( and probably
>> all IDEs),
>> can't give a list of the procedures. So for me it's just trial and
>> error ;-)
> PyScripter gives help here.
>


Or, assuming you have an instance of one (if you don't, it doesn't
really matter what attributes and methods it has, does it? :), just do
"print dir(eventObject)".

- Mike


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Introspection - was Re: Getting row / col of selected cell in ListCtrl ?

Colin J. Williams
Mike Rooney wrote:

> Colin J. Williams wrote:
>> Stef Mientki wrote:
>>> hello,
>>> ...
>>> Also a general question, where can I find what the procedures /
>>> properties a certain event has ?
>>> I find this a very intriguing question, because my IDE ( and probably
>>> all IDEs),
>>> can't give a list of the procedures. So for me it's just trial and
>>> error ;-)
>> PyScripter gives help here.
>>
>
>
> Or, assuming you have an instance of one (if you don't, it doesn't
> really matter what attributes and methods it has, does it? :), just do
> "print dir(eventObject)".
>
> - Mike

True, but PyScripter presents the information in a more more organized
way.  It also provides access to information about sub-objects to any
depth.

Colin W.



Loading...