プロが教えるわが家の防犯対策術!

下記は、aryhogeにTextBoxオブジェクトを格納する処理です。

----------------------------------------
'a)
Dim hoge()() As TextBox = _
      {New TextBox() {txta01, txtb01, txtc01}, _
      New TextBox() {txta02, txtb02, txtc02}, _
      New TextBox() {txta03, txtb03, txtc03}}

Dim aryhoge As New ArrayList    'b)

aryhoge.Add(hoge(0))
aryhoge.Add(hoge(1))
aryhoge.Add(hoge(2))
----------------------------------------

(a)を(b)の初期値として設定するにはどのようにすればよいか、ということが質問内容です。

試しに(b)の部分を以下のようにしてみましたが、「1次元配列の値を変換できない」とのエラーが出ました。
Dim aryhoge As New ArrayList(New TextBox() {hoge(0), hoge(1), hoge(2)})

どうぞよろしくお願い致します。

A 回答 (3件)

Dim aryhoge As New ArrayList(hoge)

    • good
    • 1
この回答へのお礼

burroughs6さん
なんと。。こんな簡単なやりかたもあったのですね。。
試してみると、この方法でも問題なく動作しました。
ご回答ありがとうございました。

お礼日時:2007/10/01 17:23

'【訂正】コメントの位置がものすごくおかしい位置に(汗)



'括弧の数に注目。TextBoxの配列じゃなくて「TextBoxの配列」の配列だよね?


Dim aryhoge As New System.Collections.ArrayList(New System.Windows.Forms.TextBox()(){hoge(0),hoge(1),hoge(2)})
    • good
    • 0
この回答へのお礼

himajin100000さん
詳細な解説、ありがとうございます。
()()になるんですね。。
おかげさまでやりたいことが実現できました!
ご回答ありがとうございました。

お礼日時:2007/10/01 17:23

Public Class Q3391467


Shared Sub Main
Dim txta01 As New System.Windows.Forms.TextBox
Dim txtb01 As New System.Windows.Forms.TextBox
Dim txtc01 As New System.Windows.Forms.TextBox
Dim txta02 As New System.Windows.Forms.TextBox
Dim txtb02 As New System.Windows.Forms.TextBox
Dim txtc02 As New System.Windows.Forms.TextBox
Dim txta03 As New System.Windows.Forms.TextBox
Dim txtb03 As New System.Windows.Forms.TextBox
Dim txtc03 As New System.Windows.Forms.TextBox
Dim hoge()() As System.Windows.Forms.TextBox = _
      { _
      New System.Windows.Forms.TextBox() {txta01, txtb01, txtc01}, _
New System.Windows.Forms.TextBox() {txta02, txtb02, txtc02}, _
      New System.Windows.Forms.TextBox() {txta03, txtb03, txtc03} _
      }

Dim aryhoge As New
'括弧の数に注目。TextBoxの配列じゃなくて「TextBoxの配列」の配列だよね?
System.Collections.ArrayList(New System.Windows.Forms.TextBox()(){hoge(0),hoge(1),hoge(2)})




End Sub

End Class
    • good
    • 1

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています