本文介绍了列表视图中的项目和子项目.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们.我是新手程序员如您所见,其中说明了在数据网格视图到列表视图中获取价值的代码.当我单击添加按钮时,数据网格视图中第二个单元格的项在列表视图的第一个单元格中向上移动(这是我想要的),而子项则是数据网格视图中第三个单元格的子项向上移动在列表视图的第二个单元格上向上,但是!我去第二排和第二单元格..我不知道该怎么办.感谢您的提前帮助. :)
私有 Sub btnAdd_Click( ByVal 发件人 As 系统.对象, ByVal e As System.EventArgs)句柄 btnAdd.Click Dim 列表 As 新建 ListViewItem 如果 dataGrid2.SelectedRows.Count> = 0 >然后 对于 每个行 As DataGridViewRow 在 dataGrid2.SelectedRows中 bookList.Items.Add(row.Cells( 1 ).Value.ToString()) list.SubItems.Add(row.Cells( 2 ).Value.ToString()) bookList.Items.AddRange(新建 ListViewItem(){list}) 下一步 其他 MsgBox(" 选择一本书!" ,MsgBoxStyle.Exclamation," 警告" ) 结束 如果 结束 子
解决方案
hi guys. im a newbie programmer
As you can see my code for getting value in the data grid view to list view is stated there. when I click add button, the item of the 2nd cell from the data grid view is going up on the first cell of the list view (which is what I want), and the sub item which is from the 3rd cell of data grid view is going up on the 2nd cell of the listview, BUT!! i goes on the 2nd row and 2nd cell.. I don''t know what to do. thanks for helping in advance. :)
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim list As New ListViewItem If dataGrid2.SelectedRows.Count >= 0 Then For Each row As DataGridViewRow In dataGrid2.SelectedRows bookList.Items.Add(row.Cells(1).Value.ToString()) list.SubItems.Add(row.Cells(2).Value.ToString()) bookList.Items.AddRange(New ListViewItem() {list}) Next Else MsgBox("Select a Book!", MsgBoxStyle.Exclamation, "Warning") End If End Sub
解决方案
这篇关于列表视图中的项目和子项目.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!