Help on ListCtrl Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Help on ListCtrl

Post by Nick » Wed May 13, 2020 3:49 pm

I'm having a hard time trying to create my first ListCtrl with 2 columns and 2 Rows to study how it works.
I couldn't find any complete examples on the internet. The ones I always found missing, something in the code and they don't work.
But I ended up wondering what I could use for control!

I created a Struct with a Grid. Then I removed Struct, and left only the Grid.
That's when I thought instead of using a Grid I could use a simpler control.

I don't like the Grid because it doesn't correctly select the whole line, it's half pretending to be selected
In ListCtrl when selecting a row, it is perfectly selected without flaws, different from the grid

My Objective is to read a file that I have formed as a table, to the Control
As an example I would have 2 columns and 2 rows only
Then what I'll do is save the data in the file and read from the file.
The only thing this control will do is display the data, that's all.

Which one should I use for this purpose? At first I thought ListCtrl was good, but I was in doubt about DataViewCtrl.

And if someone knows how to do it, could they leave me a super simple example of a control like this with 2 columns and 2 rows, for me to study how it works so that I can then implement what I need!

Thank you to anyone who can help!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Help on ListCtrl

Post by ONEEYEMAN » Wed May 13, 2020 4:27 pm

Hi,
How may rows/columns do you need?
Do youneed to use an additional controls inside? Like use a button in some cells.
Do you need to use DnD operation?

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 14786
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Help on ListCtrl

Post by doublemax » Wed May 13, 2020 4:36 pm

Code: Select all

wxListCtrl *lc = new wxListCtrl(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );

lc->AppendColumn( "col1" );
lc->AppendColumn( "col2" );
lc->AppendColumn( "col3" );

for(int i=0; i<20; i++ )
{
  long item = lc->InsertItem( i, wxString::Format("item%d col%d", i, 0) );
  lc->SetItem( i, 1, wxString::Format("item%d col%d", i, 1) );
  lc->SetItem( i, 2, wxString::Format("item%d col%d", i, 2) );
}
Use the source, Luke!

Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Help on ListCtrl

Post by Nick » Wed May 13, 2020 4:57 pm

ONEEYEMAN wrote:
Wed May 13, 2020 4:27 pm
Hi,
How may rows/columns do you need?
Do youneed to use an additional controls inside? Like use a button in some cells.
Do you need to use DnD operation?

Thank you.
2 Columns and 2 Lines as I informed in the question is already enough. But, The example that doublemax left already serves because I was able to mount a simple model with that

I will use nothing but plain text
I don't know what DnD is

The question left is whether to use ListCtrl or DataViewCtrl

Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Help on ListCtrl

Post by Nick » Wed May 13, 2020 4:58 pm

doublemax wrote:
Wed May 13, 2020 4:36 pm

Code: Select all

wxListCtrl *lc = new wxListCtrl(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );

lc->AppendColumn( "col1" );
lc->AppendColumn( "col2" );
lc->AppendColumn( "col3" );

for(int i=0; i<20; i++ )
{
  long item = lc->InsertItem( i, wxString::Format("item%d col%d", i, 0) );
  lc->SetItem( i, 1, wxString::Format("item%d col%d", i, 1) );
  lc->SetItem( i, 2, wxString::Format("item%d col%d", i, 2) );
}
This example was great to study! I can understand the basics now so I can study his documentation.
I've even managed to do that. I learned how to use Insert and manually create the row and column texts

Code: Select all

   ListCtrl->InsertColumn(0, "col1");
   ListCtrl->InsertColumn(1, "col2");
   ListCtrl->InsertColumn(2, "col3");

   ListCtrl->InsertItem(0   , "Text1");
   ListCtrl->SetItem   (0, 1, "Text2");
   ListCtrl->SetItem   (0, 2, "Text3");
   
   ListCtrl->InsertItem(1   , "Text1");
   ListCtrl->SetItem   (1, 1, "Text2");
   ListCtrl->SetItem   (1, 2, "Text3");

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Help on ListCtrl

Post by ONEEYEMAN » Wed May 13, 2020 5:31 pm

Hi
wxDVC is a very complex.
You should stick with WILL.

For the future reference - DnD is 'drag-and-drop'

Thank you.

Nick
Earned some good credits
Earned some good credits
Posts: 107
Joined: Thu Apr 11, 2019 12:50 am

Re: Help on ListCtrl

Post by Nick » Wed May 13, 2020 5:39 pm

ONEEYEMAN wrote:
Wed May 13, 2020 5:31 pm
wxDVC is a very complex.
For the future reference - DnD is 'drag-and-drop'
Good to know!

Post Reply