-1

I have a table layout panel with something like 150 rows. each row has 6 columns, and in each column I have a text label.

In my program, I want the user to be able during run time to decide which rows he wants to see, so he can select multiple rows, and then say "remove" from table. he can also do "undo" then the rows reapear again.

how I do it? I first create the tlp and labels dynamiclly: the rows height is set to 0 and the labels' visibility is set to false. Then the user chooses rows to see and then I increase the row height and make the labels' visibility to true.

the problem is that I have something like 800 labels, and it take a lot of time for the table to generate it self...

I am sure there is a way fixing this but I have no idea...

thank you!

TheDaJon
  • 545
  • 2
  • 8
  • 24
  • 1
    Wow, `TableLayoutPanel` is definitely not designed for such scenario. You'd better consider using `DataGridView`. – Ivan Stoev Sep 13 '16 at 11:38
  • @IvanStoev and can you give me a bit of example how can I do it with data grid? – TheDaJon Sep 13 '16 at 11:44
  • create a datatable of your data, then bind it using `DataGridView.DataSource = DataTable` – Takarii Sep 13 '16 at 11:46
  • is there a way to do it with tlp? because I also need the rows to be clickable, and each time a row is selected then I want to change the row's background color and show some details... can I do it with datagrid? because with tlp it works fine, but when there is a lot of labels it is slow... – TheDaJon Sep 13 '16 at 12:20
  • There are tons of examples. `DataGridView` is basically what are you explaining - rows and columns presented in tabular format. Cells (the intersection of each row with each column) represent your labels. – Ivan Stoev Sep 13 '16 at 12:20
  • @IvanStoev and the rows are clickable? I can also paint the background of each row seperatly? – TheDaJon Sep 13 '16 at 12:29
  • I think so, but you could check yourself. AFAIK there are `CellClick` and `CellPainting` events, along with many others (as well as properties). – Ivan Stoev Sep 13 '16 at 12:34
  • You might take a look at http://stackoverflow.com/questions/32072960/rendering-a-generated-table-with-tablelayoutpanel-taking-too-long-to-finish/32084782#32084782 thread. – Ivan Stoev Sep 13 '16 at 12:37

1 Answers1

0

The solution I have is based on what @IvanStoev wrote at the answer he gave on the previous question.

It not the most elegant solution but it works: I just added a tableName.SuspendLayout(); before start updating the table and tableName.ResumeLayout(true); when finishing updating it, and it works much much faster.

any comments on this solution would be thankfull.

TheDaJon
  • 545
  • 2
  • 8
  • 24