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
  • 35319
    posted

    Hello greenway,

     

    I have been looking into your post and I have been trying to reproduce your issue following your scenario with no success. Setting the ‘ItemSource’ property of the XamMultiColumnComboEditor does not seem to throw any exception. I am sending you my sample project in Visual Basic version(DataGridMultiComboWithDataTableVBVersion.zip) and in C# version(DataGridMultiComboWithDataTableC#.zip).

     

    If I have misunderstood you in any way, please do not hesitate to tell me.

     

    I am looking forward to hearing from you.

    DataGridMultiComboWithDataTableVB&C#Version.zip
Reply Children