question about ListPresenter or ListView

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

question about ListPresenter or ListView

pdigonzelli
Hi all ,

I want to change some of the attributes of an row of a ListView based a
condition of the object for that row.
I want change the background color or the icon. But I do not understand how
can i do that.

Some one help me?

Thanks in advance


Pablo


Reply | Threaded
Open this post in threaded view
|

Re: question about ListPresenter or ListView

Chris Uppal-3
Pablo Digonzelli wrote:

> I want to change some of the attributes of an row of a ListView based a
> condition of the object for that row.
> I want change the background color or the icon. But I do not understand
> how can i do that.

You can change the icon in two ways.  The simplest, but least general, is to
provide an implementation of #icon in the objects displayed in each row.  More
flexibly, you can set the #getImageBlock of the list view (or of the column
itself) to a Block that takes the row object as its single parameter, and
answers not the Icon, but the #imageIndex of the icon, you want.

E.g.

    [:it | (it isOk ifTrue: [true icon] ifFalse: [Icon warning])
                imageIndex]

If the condition is at all complex, or if it needs to invoke the owning
Presenter, then it's much easier to set the #getImageBlock from code somewhere
(e.g. in #model: or #onViewOpened) rather than trying to type it into the View
Composer.

Setting the background colour is similar, but a bit more complicated.  In this
case you have to set the #customDrawBlock of the list view.  Again it's easiest
to do that in the #onViewOpened method.  If you are using an enhanced list view
in its #report mode, then I think that you have to set the #customDrawBlock's
of all the columns.  The block(s) takes an NMLVCUSTOMDRAW as its single
parameter (or a NMTVCUSTOMDRAW if you try the same thing with a TreeView).  You
can make the text bold with code like:

    anNMLVCUSTOMDRAW font beBold.

or set the background colour with:

    anNMLVCUSTOMDRAW backcolor: Color red.

I imagine it'd be better to create and cache the Color rather than creating a
new one each time (if you aren't using a system colour as in this example), but
I don't really know for sure.

If you need or want better control over the drawing of the whole row, then see
the comment in IconicListAbstract>>customDrawBlock:  I'd also suggest that you
got hold of John Aspinal's excellent EditableListView
<http://www.solutionsoft.co.uk/> which does its own custom drawing and is
therefore a good source of sophisticated examples.

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: question about ListPresenter or ListView

pdigonzelli
Thanks Chris, both works for me.

Pablo

"Chris Uppal" <[hidden email]> escribió en el
mensaje news:[hidden email]...
> Pablo Digonzelli wrote:
>
> > I want to change some of the attributes of an row of a ListView based a
> > condition of the object for that row.
> > I want change the background color or the icon. But I do not understand
> > how can i do that.
>
> You can change the icon in two ways.  The simplest, but least general, is
to
> provide an implementation of #icon in the objects displayed in each row.
More
> flexibly, you can set the #getImageBlock of the list view (or of the
column

> itself) to a Block that takes the row object as its single parameter, and
> answers not the Icon, but the #imageIndex of the icon, you want.
>
> E.g.
>
>     [:it | (it isOk ifTrue: [true icon] ifFalse: [Icon warning])
>                 imageIndex]
>
> If the condition is at all complex, or if it needs to invoke the owning
> Presenter, then it's much easier to set the #getImageBlock from code
somewhere
> (e.g. in #model: or #onViewOpened) rather than trying to type it into the
View
> Composer.
>
> Setting the background colour is similar, but a bit more complicated.  In
this
> case you have to set the #customDrawBlock of the list view.  Again it's
easiest
> to do that in the #onViewOpened method.  If you are using an enhanced list
view
> in its #report mode, then I think that you have to set the
#customDrawBlock's
> of all the columns.  The block(s) takes an NMLVCUSTOMDRAW as its single
> parameter (or a NMTVCUSTOMDRAW if you try the same thing with a TreeView).
You
> can make the text bold with code like:
>
>     anNMLVCUSTOMDRAW font beBold.
>
> or set the background colour with:
>
>     anNMLVCUSTOMDRAW backcolor: Color red.
>
> I imagine it'd be better to create and cache the Color rather than
creating a
> new one each time (if you aren't using a system colour as in this
example), but
> I don't really know for sure.
>
> If you need or want better control over the drawing of the whole row, then
see
> the comment in IconicListAbstract>>customDrawBlock:  I'd also suggest that
you
> got hold of John Aspinal's excellent EditableListView
> <http://www.solutionsoft.co.uk/> which does its own custom drawing and is
> therefore a good source of sophisticated examples.
>
>     -- chris
>
>