This is a migrated thread and some comments may be shown as answers.

GridView Combo Box Column Data Binding

8 Answers 222 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fransiscus Setiawan
Top achievements
Rank 1
Fransiscus Setiawan asked on 25 May 2010, 02:58 AM
Hi,

I have a question about RadGridView

Scenario:
1. I called WCF to populate datagrid with customers table
2. I have Country Code column which is exists in the customers table as well (the value of that column is 'AU', 'ID', 'NZ, etc)
3. I would like to have a combo box that populates country code from another WCF method

current condition
1. I've added Combo Box column on the Async_Completed event of getting customers table via WCF
2. It does not display the initial value of the combo box (it shows only empty) when after the data is binded, the other data columns are displayed fine
3. I binded the country combo box on the event of beginning_edit

The combo box does not display the value from the customers table but when I click it, it displays the records in the countries table

It seems the combo box does not set the value based on the itemcontext of the gridview
Cheers

8 Answers, 1 is accepted

Sort by
0
Fransiscus Setiawan
Top achievements
Rank 1
answered on 26 May 2010, 04:30 AM
has anyone got idea how to achieve this?

Cheers
0
Pavel Pavlov
Telerik team
answered on 26 May 2010, 09:50 AM
Hello Fransiscus Setiawan,
It seems you have hit a known issue with the combo column. Due to the async nature of the service call the ItemsSource arrives later  and the column fails to update.

This issue was addressed soon . Please try downloading the latest internal build. It should fix the problem . The latest internal builds are available for download in your Client.Net account.

Greetings,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fransiscus Setiawan
Top achievements
Rank 1
answered on 27 May 2010, 12:24 AM
Hi Pavel,

I still have the same issue. The latest internal build that I get from the account is 2010.1.521.1030

So basically my scenario
1. WCF method to fill the grid e.g (customers data with country as its column)
2. WCF method to fill the combo box on the grid (It can have more than one combo box column) e.g(country drop down list)

I called my WCF to bind the combo box on the upon completion of the 1st method

The binding is working as I can see items collection on the combo box, but it doesn't displayed the value from the database (1st method), I need to go to edit mode and click on the cell in order to refresh the cell and display its original value. 

Is there anything i've done wrong?

Cheers
0
Fransiscus Setiawan
Top achievements
Rank 1
answered on 31 May 2010, 02:46 AM
Hi Pavel,

Could you please confirm whether this issue has been resolved in the latest build?It seems not

Cheers
0
Pavel Pavlov
Telerik team
answered on 31 May 2010, 01:37 PM
Hello Fransiscus Setiawan,

Can you please paste me as much relevant code as you can so I can try build a repro project here. This will help me debug the problem here and provide you with solution.  ( I need to see the way you bind the combo column as well as the relevant methods that fill the data) .

Best wishes,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fransiscus Setiawan
Top achievements
Rank 1
answered on 01 Jun 2010, 12:05 AM
Hi Pavel,

This is the way I'm binding the combo box and the grid. My grid is pretty much dynamic grid by using light dataset class.

This is how the grid being binded  
 
  Private Sub GetData_Completed(ByVal sender As ObjectByVal e As wcfiRef.GetDataCompletedEventArgs)  
        If e.error IsNot Nothing Then 
            If e.aerror.ErrorType = pwcCoreLib.System.ErrorType.Exception Then 
                DisplayError(_termCodes.GetDescription("Error"), e.aerror.ErrorMessage)  
            Else 
                DisplayMessage(_termCodes.GetDescription("Error"), e.aerror.ErrorMessage)  
            End If 
            Exit Sub 
        End If 
 
        dgResults.Columns.Clear()  
        GridAddMenuColumn()  
        _dataList = DynamicDataBuilder.GetDataList(e.Result)  
        'set the type of object to be of elementtype. This will be used in adding new type  
        _CurrentObjectType = _dataList.AsQueryable.ElementType()  
        dgResults.ItemsSource = New Object() {}  
        dgResults.ItemsSource = _dataList 'DynamicDataBuilder.GetDataList(e.Result)  
 
        If (e.Result.Tables.Count > 0) Then 
            GridFormatter.GridDataFormat(dgResults, TableColumnsList, e.Result.Tables(0).Columns)  
            GridColumnBusinessLookUp(TableColumnsList)  
        End If 
 
        _isGridReady = True 
    End Sub 
 
This is how the column in the grid being added (At this point of time it just set the combo box container without any datasource), if business ID/Lookup is not null then we know that it will contain look up combo box  
 
  Public Shared Sub GridDataFormat(ByVal grid As RadGridView, ByVal lstTableColumn As List(Of TableColumn), _  
                                     ByVal Columns As ObservableCollection(Of DataColumnInfo), Optional ByVal ShowAll As Boolean = False)  
 
        Dim dateConverter As New PwCDateConverter  
 
        For Each dataColumn As DataColumnInfo In Columns  
            If (dataColumn.DisplayIndex <> -1) Then 
 
                Dim colDef As TableColumn = (From c In lstTableColumn Where c.ColumnName = dataColumn.ColumnName).FirstOrDefault()  
 
                If (Not colDef Is NothingThen 
 
                    If (colDef.intBusinessID > 0) Then 
                        Dim col As GridViewComboBoxColumn = New GridViewComboBoxColumn()  
 
                        col.UniqueName = dataColumn.ColumnName  
                        col.Header = colDef.ColumnDesc  
                        col.IsReadOnly = colDef.BtPK  
                        col.IsVisible = Not colDef.BtIdentity  
                        grid.Columns.Add(col)  
                    Else 
                        Dim col As GridViewDataColumn = New GridViewDataColumn()  
                        col.UniqueName = dataColumn.ColumnName  
                        'col.IsReadOnly = True  
                        col.IsReadOnly = colDef.BtPK  
                        col.Header = colDef.ColumnDesc  
                        col.IsVisible = Not colDef.BtIdentity  
                        'Apply custom diplay using coverters  
                        If colDef.VcType.ToLower = "datetime" OrElse colDef.VcType.ToLower = "smalldatetime" Then 
                            col.DataMemberBinding.Converter = dateConverter  
                        End If 
 
                        grid.Columns.Add(col)  
                    End If 
                Else 
                    Dim col As GridViewDataColumn = New GridViewDataColumn()  
                    col.IsVisible = ShowAll  
 
                    If (ShowAll) Then 
                        col.UniqueName = dataColumn.ColumnName  
                        grid.Columns.Add(col)  
                    End If 
                End If 
            End If 
 
        Next 
 
        dateConverter = Nothing 
    End Sub 
 
 
This is how the combo box called WCF method  
 
   Private Sub GridColumnBusinessLookUp(ByVal lstTableColumn As List(Of TableColumn))  
        Dim businessColumn = From bc In lstTableColumn Where bc.intBusinessID > 0 _  
                             Select New With {.ColumnName = bc.ColumnName, .BusinessID = bc.intBusinessID}  
 
        For Each col In businessColumn  
            wcfIReference.GetBusinessLookUpAsync(col.ColumnName, col.BusinessID, mError)  
        Next 
 
 
 
    End Sub 
 
This is the GetBusinessLookUpAsync where it binds the combo box after the wcf method is completed  
 
Private Sub GetBusinessLookUp_Completed(ByVal sender As ObjectByVal e As GetBusinessLookUpCompletedEventArgs)  
        If e.Error IsNot Nothing Then 
            If e.aerror.ErrorType = pwcCoreLib.System.ErrorType.Exception Then 
                DisplayError(_termCodes.GetDescription("Error"), e.aerror.ErrorMessage)  
            Else 
                DisplayMessage(_termCodes.GetDescription("Error"), e.aerror.ErrorMessage)  
            End If 
        Else 
            If (e.Result IsNot Nothing AndAlso e.Result.BusinessLookUp IsNot NothingThen 
                Dim colBusinessSource As GridViewComboBoxColumn = CType(dgResults.Columns(e.Result.ColumnName), GridViewComboBoxColumn)  
     
                If (colBusinessSource IsNot NothingThen 
                    colBusinessSource.ItemsSource = e.Result.BusinessLookUp  
                    colBusinessSource.SelectedValueMemberPath = "ID" 
                    colBusinessSource.DisplayMemberPath = "Description" 
                End If 
 
            End If 
        End If 
    End Sub 
 

Please let me know if you need any further information, I'm desperately need this to be resolved.
0
Fransiscus Setiawan
Top achievements
Rank 1
answered on 01 Jun 2010, 02:45 AM
Hi Pavel,

I've changed my method to do rebind after the combo box column has been populated, It's working as expected but my question is, is this the proper way?

Private Sub GetBusinessLookUp_Completed(ByVal sender As ObjectByVal e As GetBusinessLookUpCompletedEventArgs)  
        If e.Error IsNot Nothing Then 
            If e.aerror.ErrorType = pwcCoreLib.System.ErrorType.Exception Then 
                DisplayError(_termCodes.GetDescription("Error"), e.aerror.ErrorMessage)  
            Else 
                DisplayMessage(_termCodes.GetDescription("Error"), e.aerror.ErrorMessage)  
            End If 
        Else 
            If (e.Result IsNot Nothing AndAlso e.Result.BusinessLookUp IsNot NothingThen 
                Dim colBusinessSource As GridViewComboBoxColumn = CType(dgResults.Columns(e.Result.ColumnName), GridViewComboBoxColumn)  
     
                If (colBusinessSource IsNot NothingThen 
                    colBusinessSource.ItemsSource = e.Result.BusinessLookUp  
                    colBusinessSource.SelectedValueMemberPath = "ID" 
                    colBusinessSource.DisplayMemberPath = "Description" 
 
                    'need to rebind it again after the combo box being populated  
                    dgResults.Rebind()  
                End If 
 
            End If 
        End If 
    End Sub 

Cheers
0
Pavel Pavlov
Telerik team
answered on 03 Jun 2010, 10:27 AM
Hello Fransiscus Setiawan,

Your code seems OK to me  so I believe this is one of the good solutions to the problem.
By the way we have improved the ComboColumn to sense changes in the ItemsSource runtime and update the UI . We are uploading a service pack version right now . It will soon be available for download.
I believe with this version there will be no more need to call Rebind().

Regards,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Fransiscus Setiawan
Top achievements
Rank 1
Answers by
Fransiscus Setiawan
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or