VB.NET2003 を使用して、
CheckBox付のTreeViewを作成しました。
階層は3階層用意して、最下層のTextに人名・Tagにメールアドレスをセットしました。
下記のサンプルの場合、チェックを入れたDさんのメールアドレスのみを
取得したいのですが、どのよう書けばよろしいでしょうか?
ご教授いただけますよう、お願い致します。
TreeViewイメージ
□本部
□総務課
□Aさん
□Bさん
□人事課
□Cさん
■Dさん
□Eさん
□営業
□東京
□Fさん
□Gさん
TreeView作成コード
Dim parentrow As DataRow
Dim ParentTable As DataTable
For Each parentrow In ds.Tables("A").Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow.Item("SHOZOKU").ToString)
treeView1.Nodes.Add(parentnode)
''''child'''''
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode
For Each childrow In parentrow.GetChildRows("A")
childnode = parentnode.Nodes.Add(childrow("BUSHO_NAME").ToString)
''''child2''''
Dim childrow2 As DataRow
Dim childnode2 As TreeNode
childnode2 = New TreeNode
For Each childrow2 In childrow.GetChildRows("B")
childnode2 = childnode.Nodes.Add(childrow2("NAME").ToString)
childnode2.Tag = childrow2("MAIL").ToString
Next childrow2
''''''''''''''''''''''''
Next childrow
'''''''''''''''
Next parentrow
treeView1.CheckBoxes = True
No.1ベストアンサー
- 回答日時:
チェックされたのをいつ所得したいのでしょう?
チェックされた時点でいいのであれば TreeViewのAfterChekイベントで
dim nd as TreeNode
nd = e.Node
if nd.Checked then
MsgBox(nd.Tag)
end if
別のイベント たとえば別ボタンのClick時点なら
dim ndParent, ndChaild1, ndChaild2 as TreeNode
dim sb as new System.Text.StringBuilder
for each ndParent in TreeView1.Nodes
for each ndChild1 in ndParent.Nodes
for each ndchild2 in ndChild1.Nodes
if ndChild2.Chkeced then
if sb.Length <> 0 then
sb.Append( vbCrLf )
end if
sb.Append( ndChild2.Tag )
end if
next ' ndChild2
next ' ndChild1
next ' ndParent
MsgBox(sb.ToString)
といった具合になるかと
この回答への補足
教えて頂いた通り、
別のボタンクリック時にデータ取得したいと考えております。
上記内容でまずは試したいと思います。
有り難うございます。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
タイムアウトする仕組みを作りたい
-
レコードセットにnullの場合
-
subsequentとnextの違いってな...
-
pascalでの二分探索(バイナリ...
-
VB.NETでのイベントの途中終了
-
他のフォームから別のフォーム...
-
VBA public変数はどのようなこ...
-
ClickとChangeイベントの違いは...
-
Excel ユーザーフォームで計算 ...
-
エクセルVBAでテキストボッ...
-
ExcelVBAで他のファイル(proje...
-
ユーザーフォームへのデータ入...
-
チェックボックスを操作できな...
-
Matlabでsin波を使って矩形波を...
-
テキストボックスを空白にする方法
-
Excel VBAでsub,dimは何の略?
-
String型の値にスラッシュをつ...
-
【VBScript】変数のスコープ
-
【VB.NET】テキストボックスに...
-
ACCESS 除算での小数点切上げ方法
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
タイムアウトする仕組みを作りたい
-
subsequentとnextの違いってな...
-
レコードセットにnullの場合
-
verilogのcase文
-
Verilog-HDLのFF記述について
-
Why is 77+33 not equal to 100?
-
パスカル言語
-
Verilogの文法
-
pascalでの二分探索(バイナリ...
-
リスト間のアイテム移動について
-
最大公約数を再帰で求める(pas...
-
TreeViewのTag情報取得
-
整順リスト形式の英単語辞書(pa...
-
MATLABによるラグランジェ補間
-
片方のみ成り立つif分岐
-
Delphiでコンポーネント名を変...
-
変数に「.」が含まれる場合...
-
「for next」文と「if then els...
-
文字の連結がうまくいかない
-
Matlab
おすすめ情報