By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,685 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,685 IT Pros & Developers. It's quick & easy.

Help Required - Displaying A 2-D Array in VB.NET

P: n/a
GHJ
Hi there,

Could anybody tell me how, using VB.NET, I can display
the contents of a 2-dimensional array on a form in
response to an event.

The array is 20 X 6 cells and I don't want to have to
declare 120 separate labels in my form. I was looking to
use a control array for this, but these are not supported
in VB.NET.

I am quite new to VB in general, so please bear with me
if this is a very basic request.

My development environment is Windows XP professional SP1
and I am running the latest version of Visual Studio .NET
to do my development work.

Thanks.
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cor
Hi GHJ,
I think the best think you can do is look for the "for next" program
control

Something like (absolute pseudo code) I don't know nothing how you
constructed your array.
\\\
dim i,y as integer
for i = 0 to a-array.length - 1
for y = 0 to b-array.length - 1
'do something with array(i,y)
next
next
///
I hope this helps a little bit.

Cor
Nov 20 '05 #2

P: n/a
* "GHJ" <gh*********@btopenworld.com> scripsit:
Could anybody tell me how, using VB.NET, I can display
the contents of a 2-dimensional array on a form in
response to an event.

The array is 20 X 6 cells and I don't want to have to
declare 120 separate labels in my form. I was looking to
use a control array for this, but these are not supported
in VB.NET.
Creating Control Arrays in Visual Basic .NET and Visual C# .NET
<http://msdn.microsoft.com/library/?url=/library/en-us/dv_vstechart/html/vbtchCreatingControlArraysInVisualBasicNETVisualCN ET.asp>
I am quite new to VB in general, so please bear with me
if this is a very basic request.


Instead of using controls, you may want to draw the data onto the form
in its 'Paint' event handler ('e.Graphics.DrawString').

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
Cor
Hi GHJ,
I misread it, as addition to Herfried.

This is an example with buttons one dimensional array of controls,

\\\
Private mybutton(31) As Button
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim start As Integer = 4
Dim top As Integer = 25
Dim i As Integer
For i = 0 To System.DateTime.DaysInMonth(2003, 10) - 1
mybutton(i) = New Button
mybutton(i).TextAlign = ContentAlignment.MiddleCenter
mybutton(i).Width = 40
mybutton(i).Height = 20
mybutton(i).FlatStyle = FlatStyle.Flat
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Location = New System.Drawing.Point(start, top)
mybutton(i).Text = (i + 1).ToString
mybutton(i).Cursor = Cursors.Hand
Me.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
start = start + 40
If (i + 1) Mod 5 = 0 Then
top = top + 20
start = 4
End If
Next
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim month As Button = DirectCast(sender, Button)
MessageBox.Show("The day is: " & month.Text)
End Sub
End Class
///

I hope this helps a little bit?
Cor

Nov 20 '05 #4

P: n/a

Thanks to all who responded with your ideas. I have gone for the
datagrid option. Having a few minor problems but getting there.

Once again thanks a lot.

GHJ.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.