We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Dynamic combobox in GridGroupingControl

I have a GGC where I have 2 columns of comboboxes which are set as follows:
'ITEM COLLECTION

Dim oSourceColl As New StringCollection

oSourceColl.Add("A")

oSourceColl.Add("B")

oSourceColl.Add("C")

GridGroupingControl1.TableDescriptor.Columns(1).Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.ComboBox

GridGroupingControl1.TableDescriptor.Columns(1).Appearance.AnyRecordFieldCell.ChoiceList = oSourceColl

'DS DRIVEN COMBO

GridGroupingControl1.TableDescriptor.Columns(2).Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.GridListControl

GridGroupingControl1.TableDescriptor.Columns(2).Appearance.AnyRecordFieldCell.ValueMember = "Sno"

GridGroupingControl1.TableDescriptor.Columns(2).Appearance.AnyRecordFieldCell.DisplayMember = "Sno"

'DATASOURCE FILLED IN LOAD EVENT

DS1TableAdapter1.Fill(MyDataSet.DS1)

DS2TableAdapter1.Fill(MyDataSet.DS2)

DS3TableAdapter1.Fill(MyDataSet.DS3)

Everything works perfectly fine on my winform, on the cbo2_click event

If cbo1.Text = "A" Then

cbo2.DataSource = New DataView(MyDataSet.DS1)

ElseIf cbo1.Text = "B" Then

cbo2.DataSource = New DataView(MyDataSet.DS2)

ElseIf cbo1.Text = "C" Then

cbo2.DataSource = New DataView(MyDataSet.DS3)

End if

but when It comes to the GGC, I cannot get a dynamic datasource on cbo2, depending on that particular value of cbo1 on that row. Please let me know what I should do, and what event I should call

Thanks!


Nicolas

7 Replies

AS Amresh S Syncfusion Team June 6, 2016 12:15 PM UTC

Hi Nicolas, 
 
Thank you for using Syncfusion products. 
 
In order to have a dynamic datasource based on the value selected in a combobox, the QueryCellStyleInfo event can be used. In the below sample, the datasource for the SampleData column has been set based on the CategoryID column. Please make use of the below code snippet.  
 
CodeSnippet: 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
   if (e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.Name == "SampleData" 
       && e.TableCellIdentity.DisplayElement.Kind == Syncfusion.Grouping.DisplayElementKind.Record) 
   { 
      // Gets the value selected from the combobox. 
      string value = e.TableCellIdentity.DisplayElement.GetRecord().GetValue("CategoryID").ToString(); 
      if (value == "a") 
      { 
         e.Style.DataSource = table; 
         e.Style.DisplayMember = "Number"; 
         e.Style.ValueMember = "Word"; 
      } 
      else if (value == "b") 
      { 
         e.Style.DataSource = this.zipCodes.ZipCodes; 
         e.Style.DisplayMember = "City"; 
         e.Style.ValueMember = "Class"; 
      } 
      else if (value == "c") 
     { 
        e.Style.DataSource = this.northWindSet.Shippers; 
         e.Style.DisplayMember = "Shipper ID"; 
         e.Style.ValueMember = "Company Name"; 
      } 
   } 
} 
 
 
Sample: 
 
Regards, 
Amresh S. 
 



NI Nicolas June 9, 2016 01:28 AM UTC

That works like a charm!!! Thank you for the support! One last related question, what is the event to call once the combobox value is commited?

Nicolas


AK Adhikesevan Kothandaraman Syncfusion Team June 9, 2016 01:22 PM UTC

Hi Nicolas, 

Thanks for your update. 

The CurrentCellCloseDropDown event can be used to notify the values committed in the ComboBox cell. Please refer to the following code snippet, 

Code Snippet: 
this.gridGroupingControl1.TableControl.CurrentCellCloseDropDown += new Syncfusion.Windows.Forms.PopupClosedEventHandler(TableControl_CurrentCellCloseDropDown); 
void TableControl_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e) 
{ 
   if(e.PopupCloseType == Syncfusion.Windows.Forms.PopupCloseType.Done) 
   { 
       //To do 
       Console.WriteLine("ComboBox cell value is committed"); 
   } 
} 
 
Sample: 

Regards, 
Adhi 



NI Nicolas June 9, 2016 08:04 PM UTC

Hi! The 3 events worked as expected! For VB.net users, I wrote the following line in the load event

AddHandler GridGroupingControl1.TableControl.CurrentCellCloseDropDown, AddressOf TableControl_CurrentCellCloseDropDown

Now, I don't know if I have to open a new thread, but I am trying to call a value from the GGC combo having the dynamic datasource, and report it to a textbox. In a normal winform combobox, I would use :

Private Sub odoc_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles odoc.SelectionChangeCommitted

dim cbo as multicolumnCombobox = odoc

dim txtBox as string = cbo.SelectedItem.row.itemarray(1).ToString

End Sub

where the integer represents the column value of the combo datasource. You should know that my datasource is not limited to a displaymember and a valuemember, I have queries with more than 2 columns

I tried to dig in the sender and e librairy for the 3 events you have suggested with no luck to find the equivalent.

For instance, in your datagrid example, if I select the value "a" in categoryID, there are 2 columns shown : "Number", "Word". Upon selection is committed in the GGC combo, I would like to be able to use : dim txtBox as string = ....(0)... returning the column "0" value OR ...(3)... returning the Column "3" value, for the selected row.

Thank you in advance!!!

Nicolas




AK Adhikesevan Kothandaraman Syncfusion Team June 13, 2016 03:35 AM UTC

Hi Nicolas, 
 
Thanks for your update. 
 
In order to get the values of the Combobox cell, you can use the ComboBox cell renderer in the CurrentCellCloseDropDown event. Please refer to the following code snippet, 
 
Code Snippet: 
void TableControl_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e) 
{ 
    //To get the ComboBox cell renderer  
    GridComboBoxCellRenderer renderer = this.gridGroupingControl1.TableControl.CurrentCell.Renderer as GridComboBoxCellRenderer; 
    if (renderer != null) 
    { 
        this.textBox1.Text = renderer.ControlText; 
    } 
    //To get the Control text of the GridListControl  
    GridDropDownGridListControlCellRenderer gridListRenderer = this.gridGroupingControl1.TableControl.CurrentCell.Renderer as GridDropDownGridListControlCellRenderer; 
    if (gridListRenderer != null) 
    { 
        this.textBox1.Text = gridListRenderer.ControlText; 
    } 
} 
 
Sample: 
http://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBoxSelectedValues-90747412 
 
Regards, 
Adhi 
 



NI Nicolas June 13, 2016 05:07 AM UTC

Hi Adhi! The event worked like a charm, the renderer.ControlText only provided the "DisplayMember", however, I was able to come around using a query to find the other columns values - however it might be best to use the "ValueMember" in order to insure that a proper value is fetched, I could not find this value in the library. To other users reading this, you might want to use the condition "if renderer.colindex = 1 then" to get your code triggered by the targeted column. Please note that this index is only for the VISIBLE columns index, and starting with 1 - Thanks again! Nicolas


AK Adhikesevan Kothandaraman Syncfusion Team June 14, 2016 04:57 AM UTC

Hi Nicolas, 

Thanks for your update. 

We are glad to know that your problem has been solved. Please let us know, if you need any further assistance.  

Regards, 
Adhi 


Loader.
Live Chat Icon For mobile
Up arrow icon