473,800 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1992
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******** ******@TK2MSFTN GP12.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.Locati on

When you create a Control programmaticall y, 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******** *****@tk2msftng p13.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.Locati on

When you create a Control programmaticall y, 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******** ******@TK2MSFTN GP11.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
1897
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 how to link the required libraries to get ADO functionality. It was easy enough in VB. Second, I've been surviving so far with subforms but I really want to try out a grid control. I registered a grid control that was available from ordinary...
9
6689
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 looking for; Grouping (TreeGrid capabilities) Outlook style group by Built in filtering a plus but not required Works in most recent version of Visual Studio/.Net
6
1486
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 a way to dynamically shift the lower grid so it appears just below the upper grid? Thanks. -- Paul G Software engineer.
2
1863
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. It would also support scrolling, and fixed/scrollable headers/footers. Basically just like a grid control, but has the capability to use a custom control for each cell. I don't think the grid control (nor the True DB Grid .NET control that we...
0
1499
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 how many columns the grid has; the Height indicates how many rows the grid has, and the Size indicates both the Width and Height of each individual unit, or cell, on the grid (all cells are to be square, n x n). Each cell of the grid must be...
2
3467
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 another. I expected that when I moved the row pointer within the grid that the controls would point to the same row. But changing row within the grid does not automatically change the CurrencyManager.Position. How do you handle this?
3
2362
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 are incorrectly positioned. VS sets the positioning of the controls to absolute, and because the DIV is to the right of another DIV Firefox (correctly, I suspect) positions the controls absolutely, which means they are too far to the left, while...
1
422
by: sonali_aurangabadkar | last post by:
i want to edit whole grid on singel button click
0
1272
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 there is a viewstate issue here, but i could not find out where to update the state of the insertion controls. I don't want to set visibility for the insertion controls declaratively. I am not open to other solutions than what i am trying to do...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.