WinForms and the jumpy screen

  • Thread starter YankeeImperialistDog
  • Start date
Y

YankeeImperialistDog

I've never done a Windows Forms app before this one. It is one that i'm
taking over from another developer. I have two situations where i'm not sure
of.
i have an order entry screen with a valiable number of line items per order.
I've decided to use a tablelayoutpanel and grow the grid as line items are
added.
Item 1: The whole thing is jumpy. There has to be a way to smooth this out.
Item 2: the dynamic gowth doesn't work unless i set the table initially to
50+ lines and on load set it to one. Then add as i go. If i don't do this i
get an index out of range error. What's up with that?
Item3: i prefer to create a tablelayoutpanelrow function that will return a
row to be added.

OK, if some of these things are not available it's because its not really
ment to be used for what i need. Any ideas appreciated.
Thanks
 
P

Peter Duniho

YankeeImperialistDog said:
I've never done a Windows Forms app before this one.

I suppose you probably weren't given a choice. But dynamic layout is
probably not the best place to start learning the Forms API. :)
It is one that i'm
taking over from another developer. I have two situations where i'm not sure
of.
i have an order entry screen with a valiable number of line items per order.
I've decided to use a tablelayoutpanel and grow the grid as line items are
added.
Item 1: The whole thing is jumpy. There has to be a way to smooth this out.

If you change the contents of a dynamically organized UI, it will have
to adjust itself to the new contents. That necessarily will cause
things to shift, move about, etc. as items are added.

That said, you can control the points at which those changes occur by
suspending layout while you're adding things. See the SuspendLayout()
and ResumeLayout() methods of the panel classes. Any changes you make
to the table after you've called SuspendLayout() but before you call
ResumeLayout() will not be reflected visually until ResumeLayout() is
called.
Item 2: the dynamic gowth doesn't work unless i set the table initially to
50+ lines and on load set it to one. Then add as i go. If i don't do this i
get an index out of range error. What's up with that?

You are doing it wrong?

Sorry to be glib, but it's possible to dynamically add things the layout
panels without such problems. The classes wouldn't be nearly as useful
if they really did require those kinds of shenanigans. On the other
hand, it's true that the API isn't quite as intuitive to use as it could be.

In case you'd like an example of adding items dynamically, I've included
a method I wrote for a program that does that. I don't know whether
this is exactly what you're trying to do, but hopefully the example
helps (see below).
Item3: i prefer to create a tablelayoutpanelrow function that will return a
row to be added.

I don't know what that means. What "row" data type are you expecting
such a method to return?

Pete


Here's the method I wrote earlier. The caller passes an array of
strings, to be used to populate the new row in the table. The method
automatically extends the table (which starts with a single row and
column) to allow for the new row of text, and any additional columns
required:

private void _PopulateRow(string[] rgstrLine)
{
int row = tableLayoutPanel1.Controls.Count > 0 ?
tableLayoutPanel1.RowCount : 0;
int column = 0;

if (tableLayoutPanel1.ColumnCount < rgstrLine.Length)
{
tableLayoutPanel1.ColumnCount = rgstrLine.Length;
}
tableLayoutPanel1.RowCount = row + 1;

foreach (string strCell in rgstrLine)
{
Label label = new Label();

label.Text = strCell;
label.AutoSize = true;
label.Font = tableLayoutPanel1.Font;

tableLayoutPanel1.Controls.Add(label);
tableLayoutPanel1.SetCellPosition(label, new
TableLayoutPanelCellPosition(column++, row));
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top