Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
595
Custom Number of Columns in Code-Behind
posted

Hi! I want to be able to generate a data table in code-behind, with the number of columns depending on the number of rows in my data source. I have been able to do this successfully with the xamDataGrid but it seems a similar approach doesn't work for the Multi-Column Combo. The code below generates the error "An item with the same key has already been added" when applied to the multi-column combobox.

 

Sub Test() 

gridTest.DataSource = CreateTable(10).Rows ' works perfectly
cboMultiColumn.Columns.Clear()
cboMultiColumn .ItemsSource = CreateTable(10).Rows 'does not work :(
End Sub

Private Function CreateTable(cols As Integer) As DataTable
Dim dt As DataTable = New DataTable()
For i = 0 To cols - 1
dt.Columns.Add("Col " & i)
Next
dt.Rows.Add(dt.NewRow)
Return dt 
End Function

 

Parents Reply Children