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

  • Thread starter Thread starter GHJ
  • Start date Start date
G

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.
 
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
 
* "GHJ said:
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
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').
 
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
 
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.
 
Back
Top