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

Drop grid in a GridDataboundGrid

In one column of a gdbg I want to drop a grid (another gdbg) that itself has a combobox and a GridListControl. I'm having trouble following the examples. Problem is when I try and set the column properies using the binder, as I'm used to doing with gdbg's. The binder is null. Am I using the correct approach? Here is the basic code:

In the main gdbg, I instantiate the child grid and attach it to one of the colums...

// Create child grid
gridPharm = new GridDataBoundGrid();
gridPharm.ThemesEnabled = true;
gridPharm.CausesValidation = false;
DropDownGridCellModel aModel = new DropDownGridCellModel(gridDx.Model);
gridDx.Model.CellModels.Add("GridPharmDropCell", aModel);
aModel.EmbeddedGrid = gridPharm;
aModel.SupportsChoiceList = true;
...
gbc = binder.InternalColumns["Pharmacologic Plan"];
gbc.StyleInfo.CellType = "GridPharmDropCell";


In the main grid ShowingDropDown event, I populate and format the drop grid (I want to make one of the columns a combobox and another a GridListControl...

gridPharm.DataSource = dtPharm;
GridModelDataBinder binder = gridPharm.Binder;
gridPharm.Binder.SuspendBinding();

gridPharm.AllowResizeToFit = false;
gridPharm.TableStyle.Trimming = StringTrimming.EllipsisWord;
gridPharm.Model.BaseStylesMap["Row Header"].StyleInfo.CellType = "Header";
GridBoundColumn gbc;

//id
gridPharm.Model.HideCols["id"] = true;
//visitId
gridPharm.Model.HideCols["visitId"] = true;
//patientId
gridPharm.Model.HideCols["patientId"] = true;
//visitDxId
gridPharm.Model.HideCols["visitDxId"] = true;
//Drug name
gbc = binder.InternalColumns["Drug Name"];
gbc.StyleInfo.CellType = "GridListControl";
...

The code fails on gbc.styleInfo.celltype = because gbc is null. Any ideas? Thanks.

10 Replies

HA haneefm Syncfusion Team April 30, 2007 07:03 PM UTC

Hi Dan,

Thank you for your update.

Is it possible for you to upload us a minimal sample to reproduce the issue here? This will help us to analyse the issue further.

Best regards,
Haneef


DG Dan Garvin May 2, 2007 06:25 PM UTC

I've attached an application that shows the problem. It took some time to create a standalone app that didn't require the database. So, to run this, you'll need to change the form1.cs code that calls the xml files (see instances of .ReadXMLSchema and .ReadXML. Change the paths to match where you installed the application and then run it. You'll see a grid. Drop down the last column to the right and you should see the error. The error is caused because the attempt to create the renderer produced a null object. Thanks for your help.

Test_DropGrid1.zip


HA haneefm Syncfusion Team May 2, 2007 07:57 PM UTC

Hi Dan,

You can try setting the parent control of dropdown DataBoundGrid("gridPharm") control to a gridDx in LoadGridDx method . Please try the below code snippet and let me know if this helps.

//LoadGridDx method.
DropDownGridCellModel aModel = new DropDownGridCellModel(gridDx.Model);
gridDx.Model.CellModels.Add("GridPharmDropCell", aModel);
aModel.EmbeddedGrid = gridPharm;
gridDx.Controls.Add(gridPharm);
aModel.SupportsChoiceList = true;

Here is a modified sample.
ModifiedTest_DropGrid1.zip

Best regards,
Haneef


DG Dan Garvin May 3, 2007 01:06 AM UTC

Excellent. That worked. I set the gridPharm.Visible = false when the grid was added and then visible = true when displayed so that it is not seen until the drop down. Plesae see attached.

I've taken a couple more steps and have some followup questions, if you please.

1. How do I control the left location and width of the entire drop down control (as you see the right side of the grid is not showing).

2. How do I control the width of the columns in the drop down grid.

3. Can the dropdown grid columns be sorted?

4. Once the grid is dropped down, pressing the drop down button again closes it. Can I add a close button to the control?

5. Please notice that the dropdown grid now has a drop down grid list control with two columns (drug name and class). This is the same approach as the drop down grid list on the parent grid (Common diagnosis column on gridDx). How can I allow the users to sort the columns of the GridDropDownGridList?

Thank you very much.
-dan

Modified_Rev2_Test_DropGrid1.zip


DG Dan Garvin May 3, 2007 01:23 AM UTC

Forgot to ask about a flicker. When the dropdown button in gridDx (the parent grid) is pressed, you can just see the drop grid and then nothing. You have to press the dropdown button again to see the grid. For some reason, the gridDx_CurrentCellCloseDropDown event is being fired the first time the drop grid is opened. How can this be avoided? Thanks for your help.


DG Dan Garvin May 3, 2007 07:22 PM UTC

The only issue I'm still struggling with is the CloseDropDown event is fired the first time I drop down the grid drop down. I found that the this occurs when the datasource is set:

gridPharm.DataSource = dtPharm;

Any idea why this would be and how I can avoid making the user click twice on the dropdown button the first time the grid is displayed? Thanks.
-dan


HA haneefm Syncfusion Team May 3, 2007 09:28 PM UTC

Hi Dan,

1)How do I control the left location and width of the entire drop down control (as you see the right side of the grid is not showing).
>>>>
If you want to change the width of the DropDown in a GridDropDownl Cell, then you have to handle the CurrentCellShowingDropDown event, and set e.Size there. (Only the width is applicable in a GridListControl celltype, the height is determined by the DropDownRows parameter. Here is a code snippet to show this.

DropDownGridCellRenderer cr = gridDx.CurrentCell.Renderer as DropDownGridCellRenderer;
if (cr != null)
{
DropDownGridCellModel model = cr.StyleInfo.CellModel as DropDownGridCellModel;
if (model != null)
{
GridDataBoundGrid grid = model.EmbeddedGrid as GridDataBoundGrid;
if (grid != null)
{
int width = grid.Model.ColWidths.GetTotal(0, grid.Model.ColCount);
int hegiht = grid.Model.RowHeights.GetTotal(0, grid.Model.RowCount);
e.Size = new Size(width, hegiht);
}
}
}

2. How do I control the width of the columns in the drop down grid.
>>>
You can use the below code snippet to set the column width of the DropDown grid.

DropDownGridCellModel model = cr.StyleInfo.CellModel as DropDownGridCellModel;
if (model != null)
{
GridDataBoundGrid grid = model.EmbeddedGrid as GridDataBoundGrid;
if (grid != null)
{
grid.Model.ColWidths["Drug Name"] = 10;
}
}


3 & 5) Can the dropdown grid columns be sorted?
>>>>>
You can use the SortColumn method to sort the required column in a grid.
DropDownGridCellModel model = cr.StyleInfo.CellModel as DropDownGridCellModel;
if (model != null)
{
GridDataBoundGrid grid = model.EmbeddedGrid as GridDataBoundGrid;
if (grid != null)
{
grid.SortColumn(i);
}
}

4)Once the grid is dropped down, pressing the drop down button again closes it. Can I add a close button to the control?
>>>>>
You can create custom celltype, it requires a model class and a renderer class. The model class handles the serialization requirements for the control and creates the renderer class. The renderer class handles the UI requirements of the cell. This sample in \Syncfusion\Essential Studio\4.1.0.10\windows\Grid.Windows\Samples\In Depth\DerivedCellControlTutorial can be referred.

Please look at the sample for more detail
GridListEditSample.zip

Best regards,
Haneef


DG Dan Garvin May 3, 2007 10:40 PM UTC

Thanks Haneef. Any ideas on the firing of the CurrentCellCloseDropDown event when the datasource is set?
-dan


HA haneefm Syncfusion Team May 4, 2007 02:55 PM UTC



DG Dan Garvin May 4, 2007 03:40 PM UTC

Thanks for your help, Haneef.
-dan

>Hi Dan,

Please refer this.
http://www.syncfusion.com/support/forums/message.aspx?&MessageID=60405

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon