473,322 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Grid of controls

Tom
I need to make up a 'grid' of controls at run time. The controls (of which I
wrote) I will instantiate, then I need to arrange these in a row/column
layout. For example, let's say I instantiate 20 of the controls; then I want
to position them in a grid-like display (within a Windows Form) as 5 rows of
4 controls each. If the 'grid' doesn't fit within the frame of where it is
being generated then scroll bars should appear so that the user can 'scroll'
up and down or sideways to see the controls.

Has anyone done this kind of thing, and has some example code? Yes, I can
write all the code myself, but it is going to be complicated and I don't
really want to reinvent the wheel. This would be REALLY easy if somehow I
could use the grid control itself, and place each of my run-time generated
controls within each cell of the grid (thereby using the grid's row/column
format and scrolling capabilities); however, I have tried this and it
doesn't work as expected. Moreover, I've been told that it can't do this.

Any ideas? Thanks in advance.

Tom
Nov 20 '05 #1
6 1965
Hi Tom,

Grids are <much> easier than you imagine.
This is roughly what you want.

Have your controls in an array or ArrayList.

NumRows = <some number>
NumCols = Array.length / NumRows (or ArrayList.count)
dX = <some distance apart>
dY = <some distance apart>
StartX = <some position>
Y = <some position>
For RowNum = 0 to NumRows - 1
X = StartX
For ColNum = 0 To NumCols - 1
P As Point = X, Y
I = RowNum * NumCols + ColNum
ControlArray (I).Location = P
X = X + dX
Next
Y = Y + dY
Next

Set the Form's AutoScroll Property to True

Regards
Fergus
Nov 20 '05 #2
Tom
Fergus: Hmm.... this sure may work. My question is: What is the
'ControlArray (I).Location'? Is this the actual array element that contains
the control (I am storing mine in an ArrayList)? And once the controls are
in an array list, how to you get them to 'show' on the screen/form?

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:uT**************@TK2MSFTNGP12.phx.gbl...
Hi Tom,

Grids are <much> easier than you imagine.
This is roughly what you want.

Have your controls in an array or ArrayList.

NumRows = <some number>
NumCols = Array.length / NumRows (or ArrayList.count)
dX = <some distance apart>
dY = <some distance apart>
StartX = <some position>
Y = <some position>
For RowNum = 0 to NumRows - 1
X = StartX
For ColNum = 0 To NumCols - 1
P As Point = X, Y
I = RowNum * NumCols + ColNum
ControlArray (I).Location = P
X = X + dX
Next
Y = Y + dY
Next

Set the Form's AutoScroll Property to True

Regards
Fergus

Nov 20 '05 #3
Hi Tom.

Every Control has a Location. Stick a Control into an array and it <still>
has a Location. That Location can be accessed by indexing the array (as can
all the other properties).

Eg.
oListBox = make a new new list box.

Dim alArrayList As New ArrayList.
alArrayList.Add (oListBox)

alArrayList (0).Location 'Same as oListBox.Location

When you create a Control programmatically, you must place it on the Form.
If you are unsure of how that works, the best way to learn is to create a
blank Form, drop some Controls on it and examine all the code in the Form. You
must then recreate that behaviour for your own Controls.

Regards,
Fergus


Nov 20 '05 #4
Tom
Fergus: Thanks... I do understand that (I've been doing VB programming for
8+ years). What was throwing me was your use of the word 'ControlArray'...
plus the fact that when I referenced my control in the ArrayList it wasn't
showing up any intellisense - all I got was 'GetType' and that was it. So
what I did was (in pseudocode):

Dim X as MyControl

Dim al as New ArrayList
al.Add(x)

dim Z as MyControl
z=al(0)
z.Location=...
z.Text=... etc

If you just put in al(0) you get no intellisense - sure, you can still use
Location, but it doesn't prompt you anymore. And since my control (in this
case MyControl) is an internally developed control, it has a lot of 'extra'
parameters and it's too hard remembering what those are without the
intellisense.

Anyway, I think if I now work on the placement code I can figure this out.
Thanks a bunch for your help! :)

Tom

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eH*************@tk2msftngp13.phx.gbl...
Hi Tom.

Every Control has a Location. Stick a Control into an array and it <still> has a Location. That Location can be accessed by indexing the array (as can all the other properties).

Eg.
oListBox = make a new new list box.

Dim alArrayList As New ArrayList.
alArrayList.Add (oListBox)

alArrayList (0).Location 'Same as oListBox.Location

When you create a Control programmatically, you must place it on the Form. If you are unsure of how that works, the best way to learn is to create a
blank Form, drop some Controls on it and examine all the code in the Form. You must then recreate that behaviour for your own Controls.

Regards,
Fergus

Nov 20 '05 #5
Hi Tom,

|| I've been doing VB programming for 8+ years

Lol, oops, I got a bit too simplified there!! But I'm with you now - it's
the .NET stuff that's throwing you.

An ArrayList contains items of type Object. So when you access an
ArrayList item, intellisense says "it's an Object - what can I show for
Objects? - which is not a lot". To use an ArrayList item you must cast it into
what <you> already know it is, but VB doesn't. It's a bit of a pain in the bum
sometimes but necessary.

Your solution of using an intermediate variable is better anyway, for not
only do you get the intellisense back, you also don't have to keep referring
to the ArrayList for each of the properties thatt you're setting.

Regards,
Fergus

Nov 20 '05 #6
Tom
Fergus: Yep, it now works like a champ.... Well, almost. Basically, I put a
panel in my form, then dynamically instantiate the controls and place them
into a 'grid' format on that panel. I have the AutoScroll turned on and the
scroll works great - except for the 'grid' column/row headings. I ended up
putting them (the column/row heading labels) in panels also within the
scrollable panel. That works, except THEY scroll as well - off the screen.
For instance, I would like to have the row (left) headings stay on the
screen even if you scroll all the way to the right; and the top (column)
headings to 'stay' even if you scroll all the way to the bottom - i.e.
LOCKED column and row headings.

I suppose I could put them above and to the left of the panel, but then I
would have to somehow 'detect' that a scroll has occured and then scroll
those headings myself. Except I don't see any event anywhere in the panel
that gets fired when an autoscroll occurs.

I just wish there were an easy way to get these controls into a 'real'
grid - again, it would make this kind of thing a lot easier to handle since
the headings could be locked.

Tom

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:O0**************@TK2MSFTNGP11.phx.gbl...
Hi Tom,

|| I've been doing VB programming for 8+ years

Lol, oops, I got a bit too simplified there!! But I'm with you now - it's the .NET stuff that's throwing you.

An ArrayList contains items of type Object. So when you access an
ArrayList item, intellisense says "it's an Object - what can I show for
Objects? - which is not a lot". To use an ArrayList item you must cast it into what <you> already know it is, but VB doesn't. It's a bit of a pain in the bum sometimes but necessary.

Your solution of using an intermediate variable is better anyway, for not only do you get the intellisense back, you also don't have to keep referring to the ArrayList for each of the properties thatt you're setting.

Regards,
Fergus

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: SAM | last post by:
Hey guys, Long time Access programmer, but never had to bother with these things until now. First, I use ADO all the time in VB, but now I need to use it in Access 2K. I never remember/know...
9
by: Michael Howes | last post by:
I'm looking for a power grid control to use for some C#/Windows forms development. There are a LOT of grids out there and trying to analyzes them could turn into a long task. Some things I'm...
6
by: Paul | last post by:
Hi I have 2 data grids and several controls on a web page. The grids will vary in size, just wondering if the lower grid could be covered by part of the upper grid depending on its size or is there...
2
by: Tom | last post by:
I need to display a series of controls (in my case, a custom control) in a grid-like fashion. This means this particular control would be repeated multiple times, arranged in a row/column format....
0
by: Workgroups | last post by:
Not sure the best way to go about making this: I have 3 user defineable values - Width, Height, and Size. These values need to define a "grid" of some kind in the following manner: The Width is...
2
by: C Glenn | last post by:
I have both a DataGrid and collection of data editing controls within a form connected to the same table within the same DataSet with a CurrencyManager. But they don't remain in sync with one...
3
by: Dave | last post by:
I am designing a web page using VS2003 ASP.NET. The page contains various DIVs (panels), one of which is in grid layout. The controls in this DIV render correctly in IE, but when using Firefox they...
1
by: sonali_aurangabadkar | last post by:
i want to edit whole grid on singel button click
0
by: patogenic | last post by:
I want to use the grid for record insertion. Everything works fine except after saving the new record; all controls for record insertion are still visible besides the "Add New" button. I think...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.