Create listctrlitme first, then add it , create shortcuts for creating the kind of item you want, AddRedItem( $listctrl, "stuff it says" ); ....

wx-listctrl-coloritems-findselect.pl

#!/usr/bin/perl -- ## wx-listctrl-coloritems-findselect.pl ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Wx 0.86 qw( ); Main( @ARGV ); exit( 0 ); sub Main { my $app = Wx::SimpleApp->new; my $f = Wx::Frame->new( undef, -1, "", ); my $t = Wx::TextCtrl->new( $f, -1, "", ); my $lb = Wx::ListCtrl->new( $f, -1, [ -1, -1 ], [ -1, -1 ], Wx::wxLC_REPORT() | Wx::wxLC_NO_HEADER() | Wx::wxLC_SINGLE_SEL +() | Wx::wxLC_SORT_ASCENDING() ); my @str = ( map( { 'one' . $_ } 1 .. 4 ), map( { 'two' . $_ } 22 .. 33), ); for my $str ( sort { rand(1) <=> rand(1) } @str ) { my $item = Wx::ListItem->new; $item->SetText( $str ); my $col = ( Wx::wxRED(), Wx::wxBLUE(), Wx::wxBLACK(), Wx::wxGR +EEN() ) [ int rand 4 ]; $item->SetTextColour( $col ); $lb->InsertItem( $item ); } $lb->InsertColumn( 0, "" ); ## still need it, even without head +er $t->SetFocus; $f->SetSizer( Wx::BoxSizer->new( Wx::wxVERTICAL() ) ); $f->GetSizer->Add( $t, 0, Wx::wxEXPAND() ); $f->GetSizer->Add( $lb, 1, Wx::wxEXPAND() ); $f->GetSizer->SetSizeHints( $f ); $f->Show( 1 ); $app->SetTopWindow( $f ); Wx::Event::EVT_TEXT( $app, $t, \&findSelect ); $app->{t} = $t; $app->{lb} = $lb; $app->MainLoop; } ## end sub Main sub findSelect { my( $app, $ev ) = @_; my $search = lc $app->{t}->GetValue; $search =~ s/\W//g; my $lb = $app->{lb}; my $startix = 0; for my $ix ( $startix .. -1 + $lb->GetItemCount ) { my $t = $lb->GetItemText( $ix ); if( length $search and $t =~ m/$search/ ) { warn "found $search at $ix as $t \n"; $lb->SelectItem( $ix ); $lb->EnsureVisible( $ix ); last; } } } ## end sub findSelect sub Wx::ListCtrl::SelectItem { shift->SetItemState( shift, Wx::wxLIST_STATE_SELECTED(), Wx::wxLIST_STATE_SELECTED() ); } ## end sub Wx::ListCtrl::SelectItem sub Wx::ListCtrl::GetLastSelectedItem { ( shift( @_ )->GetSelectedItems )[-1]; } ## end sub Wx::ListCtrl::GetLastSelectedItem sub Wx::ListCtrl::GetSelectedItems { my $self = shift; my $count = $self->GetSelectedItemCount; return if not $count; my @items; my $item = -1; while( 1 ) { $item = $self->GetNextItem( $item, Wx::wxLIST_NEXT_ALL(), Wx::wxLIST_STATE_SELECTED() ); last if -1 == $item; push @items, $item; } die "The impossible happened , SelectedItemCount doesn't match ! " if @items != $count; @items; } ## end sub Wx::ListCtrl::GetSelectedItems

https://metacpan.org/source/MBARBON/Wx-Perl-ListView-0.01/example/listview.pl is much easier to use


In reply to Re^2: How do i color font in a listbox? ( wx-listctrl-coloritems-findselect.pl ) by Anonymous Monk
in thread How do i color font in a listbox? (Solved!!!) by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.