Solved

Control Array for vb.net Datagridview

Posted on 2011-09-07
6
537 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 22

Expert Comment

by:plusone3055
ID: 36495373
0
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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