|
-
Dec 5th, 2014, 10:58 AM
#2
Lively Member
Re: How to programmatically add columns with data to listview or datagridview?
not sure about listviews, but in Datagridviews its easy..
In my example, I have an array called CollectDataArray(12,45) which I loop through,.
12 rows, 45 columns.
' first we define the head for each column.
DataGridView1.ColumnCount = 45
For C As Integer = 0 To 44
DataGridView1.Columns(C).Name = "Col" & C
Next
' now we write the data to the cells/ rows.
For n As Integer = 0 To UBound(CollectDataArray, 2) - 1
Dim dgvRow As New DataGridViewRow
Dim dgvCell As DataGridViewCell
For p As Integer = 0 To 44
dgvCell = New DataGridViewTextBoxCell()
dgvCell.Value = CollectDataArray(p, n)
dgvRow.Cells.Add(dgvCell)
Next
DataGridView1.Rows.Add(dgvRow)
Next
DataGridView1.Refresh()
I'm sure you can take this apart to build a few columns. I just keep this code to dynamically build DGVs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|