Solved

Control Array for vb.net Datagridview

Posted on 2011-09-07
6
538 Views
Last Modified: 2012-05-12
Does anyone know if possible to make a control array of datagridviews?  Currently I have 4 grids with four unique names, like:
   dgv1, dgv2, dgv3, dgv4

I would like one control  dgv(0), dgv(1), dgv(2), dgv(3)  so I can make all my click events etc easier to program, and also set properties.

If I weren't so old school I'd understand how to make a dgv class and then create the new grids inheriting all the properties from the class.  Also, I've heard that you can make a click event routine (or any routine) apply to multiple objects but not sure how.
0
Comment
Question by:LovinSpoonful
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36495401
Sure it is. For example:

Dim dgViews(4) As DataGridView

Open in new window


Although, you might find it easier to work with a List of such:

Dim dgViews As New System.Collections.Generic.List(Of DataGridView)

dgViews.Add(new DataGridView())

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
ID: 36495511
Put the grids in a generic list (Of String) for the collection.
To have all the grids have asingle event handler, just add all the grid names to the event handles clause.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:strickdd
ID: 36495817
If you add them to a generic list, an array of DataGridViews, or any other collection, you will still need to loop through those and set each property/event:

Dim myGrids As List(Of DataGridView) = new List(Of DataGridView)

myGrids.Add(dgv1)
myGrids.Add(dgv2)
.
.
.
myGrids.Add(dgvn)

foreach grid As DataGridView in myGrids
   AddHandler grid.Click, AddressOf MyClickFunction
   grid.Rows.Add(new Row)
   'etc.
loop
0
 
LVL 15

Expert Comment

by:x77
ID: 36496057
Array only simplify any repetitive task:

  For each Dgv in new DataGridView(){Dgv1,Dgv2,Dgv3}
        dgv.property = xxx
        AddHandler Dgv.CellContentClick, addressof MyMethod
        .....
  next
0
 

Author Closing Comment

by:LovinSpoonful
ID: 36496548
Thank you all for your comments!!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question