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

GridGroupingControl How to change colum datasource based on another column selection...

Say I have one column Country and next City...
Based the user selection in Country column (combo drop down column) the user should see the appropriate citi combo drop down in the city column to select from... any help is appreciated


3 Replies

AD Administrator Syncfusion Team May 7, 2008 11:25 AM UTC


Hi GKrish,

Thanks for the interest in Syncfusion products.

You can handle CurrentCellShowingDropDown and can the change the DataSource of the other ComboBox to different DataSource. Please refer the following code snippet that shows how we can change the DataSource of the ComboBox base on the other DropDown.


private void gridDataBoundGrid1_CurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
if(cc.ColIndex == 3)
{
GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
cr.ListBoxPart.Items.Clear();
switch(this.gridDataBoundGrid1[cc.RowIndex,cc.ColIndex - 1].Text)
{
case "One":
cr.ListBoxPart.Items.Add("1");
break;
case "Two":
cr.ListBoxPart.DataSource = null;
break;
case "Three":
{
for(int i= 0; i < items3.Count; i++)
cr.ListBoxPart.Items.Add(items3[i]);
break;
}
case "Four":
cr.ListBoxPart.DataSource = theArrayList;
break;
case "Five":
cr.ListBoxPart.Items.Add("2");
break;
}
}
}



Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73330/main.htm

Please let me know if this helps.

Regards,
Asem.




AD Administrator Syncfusion Team May 9, 2008 05:44 PM UTC

Thanks that helped.. however there are few issues...

even though I set the combo for different datasource or null based on the input provided... and such.. if the user double click in the combo box it picks up values which is not empty combo box, but shows values...

secondly in addnewrecord row.. more that 2 times i am unable to select cobo box items.. i.e after adding w rows, the combo box selection the 3rd time around always becomes empty and not identifying what was selecetd...
any help is appreciated



AD Administrator Syncfusion Team May 12, 2008 10:31 AM UTC

Hi GKrish,

The DataSource for a specific cell can also be changed dynamically by handling the Model.QueryCellInfo event. Querying the style info of a cell using grid[rowindex, colindex].text in the QueryCellInfo will fire the event again and will lead to a recursive call. We can set a flag in the ClosedCellDropDown when a particular value is selected and assign the datasource only when the flag is set. In the attached sample choose the value "One" in cell 2,2 to change the DataSource for a ComboBox in the Cell 3,3.



private void gridModel_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.ColIndex == 3 && e.RowIndex == 3)
{
e.Style.CellType = "ComboBox";
e.Style.ChoiceList = null;
}
if(e.ColIndex == 3 && e.RowIndex == 3 && flag)
{
StringCollection items = new StringCollection();
items.Add("A");
items.Add("B");
items.Add("C");
items.Add("D");
items.Add("E");
e.Style.ChoiceList = items;
}
}

private bool flag = false;
private void gridDataBoundGrid1_CurrentCellCloseDropDown(object sender,

Syncfusion.Windows.Forms.PopupClosedEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
if(cc.ColIndex == 2 && cc.RowIndex == 2)
{
flag = false;
GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
if (cr.ControlText == "One")
{
flag = true;
}
else
flag = false;
}
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/F73330B/main.htm

You can also refer the following forum thread that discus about this.

http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=42073

Please let me know if this helps.

Regards,
Asem.



Loader.
Live Chat Icon For mobile
Up arrow icon