Horizontal scrollbar in table

Hi All:

I am building a table and haven’t found a way to get a horizontal scrollbar to show up (the vertical one is there). Related to this, I would like to set column widths so that all the headers are visible. As I work from left to right in the table doing this, by the time I have used up the 8 or so inches of the table width, the last half dozen columns have been reduced to 1/8" and show just ellipses as headers. Hope this is clear. Regards, D. Lewis

David,

Good question. Actually, your two questions have the same answer. The answer lies in the Auto-Resize Mode property of the Table component. This property, which is probably set to “Subsequent Columns”, controls how columns are sized within the table’s width. If you don’t want the column’s width to be constrained by the table’s width, set the Auto-Resize Mode to “Off”. This will enable horizontal scrolling.

To set the columns’ width in this mode, simply switch the designer to preview mode and resize the columns with the mouse (as you were trying to do). Then, open up the column customizer and close it - this locks in the column widths.

Hope this helps
Carl

Ok, more thoughts on column widths: I have two tables on the same window (the operators can plan orders for separate sections of the machine here), and I’m having a hard time getting both tables to display the same column width no matter how careful I am. In another thread, you mentioned that there might be a way to programatically set the width. Is that an option? That way, I could make one table the master, and if I (or they) resized a column, the other table would follow suit automatically.

Also, I was wondering if you have any thoughts on different methods of indicating to the operator which row is selected. Right now, I just change the color of the row when they select one, and that works ok. But I also use the color of the row to indicate the order status (waiting, running, complete, etc), and my “selected row” color overrides this. Is there a way to use html codes to maybe outline a row, or to bolden and italicize the text when it’s selected instead? edit: I read through Travis’ very helpful tutorial, and it looks like changing the font and text color will be easy. Let me see how far that takes me…

Yes, you can set column widths programmatically. Before I show you how, a disclaimer:

I don't want to hear any complaints about how techniques like the one I am about to present are 'undocumented'. We're getting into Java Swing here - this isn't part of the FactoryPMI component API. If you want to be able to come up with stuff like this on your own, read up on Java Swing, it's very well documented.

Ok, sorry about that, I just am wary of posting stuff like this. This script will synch the widths of the columns in Table 2 to the widths in Table 1. I put it on a timer, since there is no event to listen to to know when the widths of table 1 were modified. Also, it assumes that there is the same number of columns in both tables.

[code]t1=event.source.parent.getComponent("Table 1").getComponent(0).getComponent(0)
t2=event.source.parent.getComponent("Table 2").getComponent(0).getComponent(0)

for c in range(t1.columnModel.columnCount):
col1 = t1.columnModel.getColumn(c)
col2 = t2.columnModel.getColumn(c)
if col2.preferredWidth != col1.width:
col2.preferredWidth = col1.width[/code]

Well, no, currently the only way (without bending over backwards trying to get dynamic html into your dataset based on the curent row - ick) is to use color. Note that you can use a semi-transparent color, which will preserve the underlying color somewhat. (semi-transparent white should look like a nice 'highlight'.

The path of least resistance however would simply be to stop using color of the row to indicate order status, and instead use something like an image-based column, or some other means of indicating the row status. That way, background color can mean selection, and something else can mean order status.

Hope this helps,

Thanks Carl. I’ll see what the transparent color does for me. Row colors are more suitable in this particular case, because the operator can glance at the screen from 10 feet away, and know the run status of most of the orders.

The Java Swing code will work great. I promise I won’t complain.

You could easily modify other objects on the screen in a variety of ways. By selecting the table's selectedRow property as the driving property of the style, you can change text, images, colors, formatting, etc of another component.

Ok, I think I’m over my head a little bit. It relates to columns, so I’ll use this thread.

Here’s what I’ve done: I have a table with 13 columns. Obviously, to populate the table I use a select query. And normally, I can then go to the Table Customizer and give new names for the columns.

But in this case, in the select statement I am using “Convert” to format the data on three columns. The data displays exactly how I want it, but I cannot assign column names. In fact, two of the three columns don’t even show up in the customizer, but they show up in the table at runtime and in the designer.

Also, if I modify the data set itself by adding columns, the columns show up in the customizer, but only until the first poll. Then they disappear again.

It most likely has something to do with how I’m handling the columns. In my MSSQL table, the three columns are called StartTime, EndTime, and ElapsedTime. The first two are DATETIME data types, and the third is an INT, populated with a DATEDIFF query (UPDATE OrderEntry SET ElapsedTime = DATEDIFF (s,starttime , endtime ) ) in an action item in FactorySQL.

In my table, I only want the time in DATETIME to display, so instead of saying "SELECT …, StartTime, … etc), I wrote “SELECT …, (select convert(varchar(10), starttime, 108)), …”. So, I’m actually converting the starttime (and endtime) to a string. For the ElapsedTime, I also convert it to a string, using “SELECT …, (SELECT CONVERT(varchar(2), ElapsedTime / 3600) + 'h ’ + CONVERT(varchar(2), ElapsedTime % 3600 / 60) + 'm ’ + CONVERT(varchar(2), ElapsedTime % 60) + ‘s’), …” to give me a 0h 0m 0s format from the INT DIFF.

The data is displayed exactly how I want it on the table, but I just can’t give labels to the columns. What am I doing wrong?

I’m deploying this upgrade of Monday, so if anyone wants to jump in with suggestions, go for it.

Hi Step7,

I don’t know if this will help but when I create a calculated field in a SELECT statement I would normally give it a name using the AS keyword i.e. SELECT (calculation to produce field) AS Myname. ‘Myname’ should then be used as the column name.

I’m more used to MySQL so this may not apply to MSSQL…

Thanks Al. I gave it a try, but with the same results. I did narrow down where the column names disappear though (nothing to do with polling). If I add the columns in the data set (using the button next to the table bind button), the columns show up, and I can even add names in the customizer. But as soon as I save the project, they disappear agaiin.

Ok, after some research in Java Swing, I’ve got a hack that works:

col1 = t1.columnModel.getColumn(10)
col2 = t2.columnModel.getColumn(10)
col1.setHeaderValue(“Start”)
col2.setHeaderValue(“Start”)
col1 = t1.columnModel.getColumn(11)
col2 = t2.columnModel.getColumn(11)
col1.setHeaderValue(“End”)
col2.setHeaderValue(“End”)
col1 = t1.columnModel.getColumn(12)
col2 = t2.columnModel.getColumn(12)
col1.setHeaderValue(“Run Time”)
col2.setHeaderValue(“Run Time”)

I dropped it in the timer that controls the column widths, re: the earlier examples in the thread. Obviously, this isn’t the best place, but it works for now.

That said, I can see how this could be useful. My customers have different names for the same thing, and now it looks like I could give them a configuration screen where they could enter their own column names, and then I could just iterate through them (I assume when the screen opens). Does this make sense?

Your hack seems fine, but the “AS” keyword definitely should have worked. A calculated column gets a really weird (long, lots of invalid characters) column name without an AS keyword. All column configuration is keyed off of the column name.

e.g. SELECT convert(...) AS MyColumn FROM MyTable

I’ll try it again, but if I remember right I did it just like you describe. The only thing I’m not sure about is if I used the same names in the database or not; would that matter? I think I used something like tStartTime, tEndTime, etc.

I’ll dig further…

You should put double-quotes around the AS name to make sure it is interpreted as a name literal.