Quote Originally Posted by hb21l6 View Post
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.
Interesting thought, but not exactly what I need.

I have 5 checkboxes representing 5 columns in the grid with statistical data. 3 columns in the grid are mandatory and should always be visible. So that is 8 columns total if everything is selected.

For this scenario, I would just love to build my grid "by column" instead of "by row". If I do it "by row" I have to keep track of which columns are chose, and what their position/name is. I don't like hard coded indexers or magic strings.

It would be a two way solution, with:

1) Add the columns to the grid, with an if(chkColumnX.checked) for each of the optional columns.

2) Second when I start adding the row data, I need to know which columns the user actually selected. I don't know which of the optional ones the user selected, therefor I have no way of knowing by index which columns I have in the grid. SOmething like

var item = new DataListItem;
item.text = "Col0Value";

item.Subitems.Add("col1Value");
item.Subitems.Add("Col2Value");

... then which of the optional columns should go here???? It could be any one of the 5 optional ones, if I only checked one of them. How do I link the datasource item with the columns in the grid? I need to know which of the properties in the datasource row I should put here as the next subitem. I reckon it would be equally problematical with a datagridview.

I hope this gices a better explanation of my dilemma. I really want to avoid lots of if-then cases for each of the 5 optional textboxes. I would prefer to have them once, and do everything "by column".

Any other ideas?

/Henrik