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

Dynamically changing the DataSource of a BoundColumn based on the content of a previous column

Hello, I do have a GridDataBoundGrid and I do have two bound columns: CategoryID and PartID and the data source of the PartID column I want to change dynamically based on what I select in the first column. I looks like none of the Events that I've tried: CurrentCellChanged, CurrentCellCloseDropDown. Unless the cell looses the focus, none of these events get triggered. Is there any event that gets triggered after the value gets placed in the cell ?

1 Reply

AD Administrator Syncfusion Team July 11, 2003 05:16 AM UTC

I think CurrentCellChanged is fired at any point the cell value changes. So, it should be fired when you change the cell value even if you do not leave the cell. But you probably will have an easier time if you can do things in the following manner. This assumes that all the values for the PartID are in the same table. The reason this is important is that this allows you to assign a single datasource to the gridboundcolumn.StyleInfo.DataSource as well as a single displaymember and a single valuemember. Then the idea is that when the combobox in the PartID column is dropped, you will create a new dataview on this datatable that is filtered to show exactly the values you want based on the cell value from the other grid column. You do this in CurrentCellShowingDropDown. Here is a little sample.
 
private void gridDataBoundGrid1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid.CurrentCell;
	if(cc.ColIndex == 2)
  //column that need to be filtered...
	{
		GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
		if(cr != null)
		{
			DataView dv = new DataView(dataTable1);
			dv.RowFilter = string.Format("[MyCol1] = '{0}'", this.gridDataBoundGrid1[cc.RowIndex, 1].Text);
         		((GridComboBoxListBoxPart)cr.ListBoxPart).DataSource = dv;
		}
	}
}
Now if all the values for the PartID are not from the same table that you can filter to get the correct datasource, then you try to do the same thing, ie. set the new datasource in CurrentCellShowingDropDown, but the may be addition tasks that need to be done to make sure the original cell displays are set up properly. This can require handling Model.QueryCellInfo to dynamically set the cell value for the PartID column. If this is the case, post back explaining where your dynamic datasources come from, and maybe I can suggest something else. You may want to move this discussion from this Edit forum into our Grid forum where other grid users may see it.

Loader.
Live Chat Icon For mobile
Up arrow icon