Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Control Array for vb.net Datagridview

Posted on 2011-09-07
6
Medium Priority
?
546 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 2000 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
Technology Partners: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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