Hi folks,
I am wondering how to show expand/collapse when there are no child rows. The reason is, I want to show an empty child row if there are no child rows. Any suggestions are welcome.
I am databinding my hierarchical grid manually to a generic list (eg: a list of categories, each of which can contain a list of products). Also, I am not sure how to add a new row (to the bottom of the grid) in the parent when the user clicks a button on the page.
Thanks for any help!
Marshal
Also, when I try ti edit the child rows, I get a popup exception. This happens when I edit a child row's value and click on the collapse button at its parent level. I have an onrowupdating event on the band (child) where I get the old and new values so I can see which ones are actually updated. I store these values in Viewstate and use them later for saving, if the user chooses to save.
Sure David, here you are:
<igtblh:WebHierarchicalDataGrid ID="gvUtilityDetail" runat="server" AutoGenerateColumns="False" DataKeyFields="ID" Height="350px" Width="100%" Font-Size="10pt" Key="ID" AutoGenerateBands="False" StyleSetName="Default" OnRowUpdating="gvUtilityDetail_RowUpdating" OnRowAdding="gvUtilityDetail_RowAdding" OnRowIslandsPopulating="gvUtilityDetail_RowIslandsPopulating" > <ExpandCollapseAnimation SlideOpenDirection="Auto" SlideOpenDuration="10" SlideCloseDirection="Auto" SlideCloseDuration="10" /> <ExpandButton ImageUrl="~/Images/Grid/ighg_Expand.gif" AltText="+" HoverImageUrl="~/Images/Grid/ighg_Expand.gif" PressedImageUrl="~/Images/Grid/ighg_Expand.gif"></ExpandButton> <CollapseButton ImageUrl="~/Images/Grid/ighg_Collapse.gif" AltText="-" HoverImageUrl="~/Images/Grid/ighg_Collapse.gif" PressedImageUrl="~/Images/Grid/ighg_Collapse.gif"></CollapseButton> <Columns> <igtblh:BoundDataField DataFieldName="ID" Key="ID" Hidden="true"> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="AccountNumber" Key="AccountNumber"> <Header Text="Account #" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="MeterName" Key="GuidMeter"> <Header Text="Meter" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="FuelName" Key="GuidFuel"> <Header Text="Fuel" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="SupplierName" Key="GuidSupplier"> <Header Text="Supplier" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="FuelUnitName" Key="GuidFuelUnit"> <Header Text="Fuel Unit" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="Interval" Key="Interval"> <Header Text="Interval" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="RateCode" Key="RateCode"> <Header Text="Rate Code" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="ChargeType" Key="ChargeType"> <Header Text="Charge Type" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="PreviousReadingDate" Key="PreviousReadingDate" DataFormatString="{0:d}" DataType="System.DateTime"> <Header Text="Previous Reading" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="ReadingDate" Key="ReadingDate" DataFormatString="{0:d}" DataType="System.DateTime"> <Header Text="Current Reading" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="UnitConsumption" Key="UnitConsumption" DataType="System.Double"> <Header Text="Unit Consumption" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="InvoiceCost" Key="InvoiceCost" DataFormatString="{0:c}" DataType="System.Decimal"> <Header Text="Invoice Cost" /> </igtblh:BoundDataField> </Columns> <Bands> <igtblh:Band Key="GuidUtilityRateDetail" AutoGenerateColumns="false" OnRowUpdating="gvUtilityDetailChild_RowUpdating" DataKeyFields="GuidUtilityRateDetail" DefaultColumnWidth="150px" DataMember="UtilityRateDetailList" Width="60%"> <ExpandButton ImageUrl="~/Images/Grid/ighg_Expand.gif" AltText="+" PressedImageUrl="~/Images/Grid/ighg_Expand.gif" > </ExpandButton> <CollapseButton ImageUrl="~/Images/Grid/ighg_Collapse.gif" AltText="-" PressedImageUrl="~/Images/Grid/ighg_Collapse.gif"> </CollapseButton> <Columns > <igtblh:BoundDataField Key="GuidUtilityRateDetail" Hidden="true" > <Header Text="ID" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="Name" Key="Name"> <Header Text="Rate Name" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="UnitCost" Key="UnitCost" DataFormatString="{0:c}" DataType="System.Decimal"> <Header Text="Unit Cost" /> </igtblh:BoundDataField> <igtblh:BoundDataField DataFieldName="LSCost" Key="LSCost" DataFormatString="{0:c}" DataType="System.Decimal"> <Header Text="L.S. Cost" /> </igtblh:BoundDataField> </Columns> <Behaviors> <igtblh:EditingCore EnableInheritance="true" AutoCRUD="False"> <Behaviors> <igtblh:RowAdding EnableInheritance="true"> <ColumnSettings> <igtblh:RowAddingColumnSetting ColumnKey="Name" EditorID="prRateName" /> <igtblh:RowAddingColumnSetting ColumnKey="UnitCost" EditorID="prUnitCost" /> <igtblh:RowAddingColumnSetting ColumnKey="LSCost" EditorID="prUnitCost" ReadOnly="True" /> </ColumnSettings> </igtblh:RowAdding> <igtblh:CellEditing EnableInheritance="True"> <ColumnSettings> <igtblh:EditingColumnSetting ColumnKey="Name" EditorID="prRateName" /> <igtblh:EditingColumnSetting ColumnKey="UnitCost" EditorID="prUnitCost" /> <igtblh:EditingColumnSetting ColumnKey="LSCost" EditorID="prUnitCost" ReadOnly="True" /> </ColumnSettings> </igtblh:CellEditing> <igtblh:RowDeleting EnableInheritance="True" /> </Behaviors> </igtblh:EditingCore> <igtblh:Sorting> </igtblh:Sorting> </Behaviors> </igtblh:Band> </Bands> <Behaviors> <igtblh:EditingCore> <Behaviors> <igtblh:CellEditing EnableInheritance="True" CellEditingClientEvents-ExitedEditMode="WebDataGridView_ExitedEditMode"> <ColumnSettings> <igtblh:EditingColumnSetting ColumnKey="GuidFuelUnit" EditorID="prFuelUnit" /> <igtblh:EditingColumnSetting ColumnKey="GuidSupplier" EditorID="prSupplier" /> <igtblh:EditingColumnSetting ColumnKey="GuidMeter" EditorID="prMeter" /> <igtblh:EditingColumnSetting ColumnKey="GuidFuel" EditorID="prFuel" /> <igtblh:EditingColumnSetting ColumnKey="PreviousReadingDate" EditorID="prPreviousReading" /> <igtblh:EditingColumnSetting ColumnKey="ReadingDate" EditorID="prCurrentReading" /> </ColumnSettings> <EditModeActions MouseClick="Single" /> </igtblh:CellEditing> <igtblh:RowAdding EnableInheritance="True"> <ColumnSettings> <igtblh:RowAddingColumnSetting ColumnKey="GuidMeter" EditorID="prMeter" /> <igtblh:RowAddingColumnSetting ColumnKey="GuidFuel" EditorID="prFuel" /> <igtblh:RowAddingColumnSetting ColumnKey="GuidSupplier" EditorID="prSupplier" /> <igtblh:RowAddingColumnSetting ColumnKey="GuidFuelUnit" EditorID="prFuelUnit" /> <igtblh:RowAddingColumnSetting ColumnKey="PreviousReadingDate" EditorID="prPreviousReading" /> <igtblh:RowAddingColumnSetting ColumnKey="ReadingDate" EditorID="prCurrentReading" /> </ColumnSettings> <EditModeActions EnableOnActive="True" /> </igtblh:RowAdding> </Behaviors> </igtblh:EditingCore> <igtblh:Selection CellClickAction="Row" RowSelectType="Single"> </igtblh:Selection> <igtblh:Activation Enabled="true"> </igtblh:Activation> </Behaviors> <EditorProviders> <igtblh:DropDownProvider ID="prMeter" StretchHeight="True"> <EditorControl DropDownContainerMaxHeight="200px" EnableAnimations="False" EnableDropDownAsChild="False" TextField="MeterAbv" ValueField="ID" ID="ddlMeter" Width="75px"> <DropDownItemBinding TextField="MeterAbv" ValueField="ID" /> </EditorControl> </igtblh:DropDownProvider> <igtblh:DropDownProvider ID="prFuel" StretchHeight="True"> <EditorControl DropDownContainerMaxHeight="200px" EnableAnimations="False" ID="ddlSysFuel" ValueField="ID" TextField="ValFuel" EnableDropDownAsChild="False" Width="75px"> <DropDownItemBinding TextField="ValFuel" ValueField="ID"></DropDownItemBinding> </EditorControl> </igtblh:DropDownProvider> <igtblh:DropDownProvider ID="prSupplier" StretchHeight="True"> <EditorControl DropDownContainerMaxHeight="200px" Width="75px" EnableAnimations="False" ID="ddlEnergySupplier" TextField="SupplierAbv" ValueField="ID" EnableDropDownAsChild="False"> <DropDownItemBinding TextField="SupplierAbv" ValueField="ID"></DropDownItemBinding> </EditorControl> </igtblh:DropDownProvider> <igtblh:DropDownProvider ID="prFuelUnit" StretchHeight="True" EditorControl-DisplayMode="DropDownList"> <EditorControl DropDownContainerMaxHeight="200px" EnableAnimations="False" Width="75px" ID="ddlSysFuelUnit" TextField="AbvFuelUnit" ValueField="ID" EnableDropDownAsChild="False"> <DropDownItemBinding TextField="AbvFuelUnit" ValueField="ID"></DropDownItemBinding> </EditorControl> </igtblh:DropDownProvider> <igtblh:DatePickerProvider ID="prPreviousReading"> <EditorControl ID="dpPrevious" DisplayModeFormat="d"> </EditorControl> </igtblh:DatePickerProvider> <igtblh:DatePickerProvider ID="prCurrentReading"> </igtblh:DatePickerProvider> <igtblh:TextEditorProvider ID="prRateName"> <EditorControl ID="txtRateName" MaxLength="50" Width="150px"> </EditorControl> </igtblh:TextEditorProvider> <igtblh:CurrencyEditorProvider ID="prUnitCost"> <EditorControl ID="txtUnitCost" DataMode="Decimal" MaxDecimalPlaces="2" MinDecimalPlaces="2" Width="150px"> </EditorControl> </igtblh:CurrencyEditorProvider> </EditorProviders></igtblh:WebHierarchicalDataGrid>
Here's what I do on code behind:
gvUtilityDetail.DataSource = UtilityDetailList; gvUtilityDetail.DataBind(); foreach (ContainerGridRecord row in gvUtilityDetail.Rows) row.IsEmptyParent = true;
Hi,
Can you attach the markup of your grid?
thanks,Dave
Hi David,
adding new child row when no child rows are present
Thanks for the reply. Please see the attached screenshot. I have set the isemptyparent property to true and have the rowadding behavior for the child band. I am not doing a load on demand (adding rowislands). I can see the header but not an empty row. I tried clicking around to see if it shows a textbox (from the editorprovider) like the other child rows but no luck.
Thanks,