Articles in this section
Category / Section

How to change the ComboBox datasource in WinForms GridGroupingControl?

4 mins read

Change the ComboBox datasource based on specific cell value


To modify the data source of ComboBox cells based on a specific cell value, use the e.Style.DataSource property of the QueryCellStyleInfo event.


C#

this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo; 
 
void gridGroupingControl1_QueryCellStyleInfo(object sender,GridTableCellStyleInfoEventArgs e) 
{ 
    if (e.TableCellIdentity == null || e.TableCellIdentity.Column == null) 
        return; 
    Element element = e.TableCellIdentity.DisplayElement; 
    if (element != null && element.Kind == DisplayElementKind.AddNewRecord) 
    { 
        if (e.TableCellIdentity.Column.Name == "CategoryID") 
        { 
            e.Style.CellType = GridCellTypeName.ComboBox; 
            e.Style.DataSource = id; 
        } 
        else if (e.TableCellIdentity.Column.Name == "SampleData") 
        { 
 
            e.Style.CellType = GridCellTypeName.ComboBox; 
            Record record = el.GetRecord(); 
            //Get the first column cell value 
            var value = record.GetValue("CategoryID"); 
            //Get the collection based on the first column value 
            if (value != null &&value.ToString() != string.Empty) 
            { 
                List<CasCading> source = cascadingSource[value.ToString()]; 
                //Assign the collection for second column. 
                e.Style.DataSource = source; 
                e.Style.DisplayMember = " SampleData"; 
            } 
        } 
    } 
}

VB

AddHandler Me.gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
 
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
    If e.TableCellIdentity Is Nothing OrElse e.TableCellIdentity.Column Is Nothing Then
        Return
    End If
    Dim element As Element = e.TableCellIdentity.DisplayElement
    If element IsNot Nothing AndAlso element.Kind = DisplayElementKind.AddNewRecord Then
        If e.TableCellIdentity.Column.Name = "CategoryID" Then
            e.Style.CellType = GridCellTypeName.ComboBox
            e.Style.DataSource = id
        ElseIf e.TableCellIdentity.Column.Name = "SampleData" Then
            e.Style.CellType = GridCellTypeName.ComboBox
            Dim record As Record = el.GetRecord()
            'Get the first column cell value 
            Dim value = record.GetValue("CategoryID")
            'Get the collection based on the first column value 
            If value IsNot Nothing AndAlso value.ToString() <> String.Empty Then
                Dim source As List(Of CasCading) = cascadingSource(value.ToString())
                'Assign the collection for second column. 
                e.Style.DataSource = source
                e.Style.DisplayMember = " SampleData"
            End If
        End If
    End If
End Sub

Samples:

C#: GridGroupingControl_CS

VB: GridGroupingControl_VB

 

Conclusion

I hope you enjoyed learning about how to change the ComboBox datasource in GridGroupingControl.


You can refer to our WinForms GridGroupingControl  feature tour page to know about its other groundbreaking feature representations and WinForms GridGroupingControl documentation, and how to quickly get started for configuration specifications.

 

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

 

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied