public void SaveExpandedMasterRows(GridView view) { if (view.GridControl.Views.Count == 1) { return; } SaveMasterRowsList.Clear(); for (int i = 0; i < view.DataRowCount; i++) { if (view.GetMasterRowExpanded(i)) { object key = view.GetRowCellValue(i, descriptor.keyFieldName); SaveMasterRowsList.Add(key); GridView detail = view.GetVisibleDetailView(i) as GridView; if (detail != null) { ViewState state = ViewState.Create(this, detail); if (state != null) { DetailViews.Add(key, state); state.SaveState(detail); } } } } }
private Detail ToDetail(DetailViews view) { return(new Detail { idDetail = view.idDetail, Height = view.Height, MeasureHeight = view.MeasureHeight, Width = view.Width, MeasureWidth = view.MeasureWidth, Depth = view.Depth, DepthMeasurement = view.DepthMeasurement, Image = view.Image, DescriptionAdmin = view.DescriptionAdmin, DescriptionUser = view.DescriptionUser }); }
/// <summary> /// Restores the previously expanded master rows. /// </summary> /// <param name="view">The grid view to expand in.</param> public void RestoreExpandedMasterRows(GridView view) { //TODO: Does including BeginUpdate and EndUpdate have any effect here? // A potential problem with adding BeginUpdate and EndUpdate might be that GetVisibleDetailView // does not get the correct/expected value when the grid is not updating. This needs verifying. //view.BeginUpdate(); //try //{ //Collapse all master rows. view.CollapseAllDetails(); //Foreach saved key value foreach (var value in SavedExpandedMasterRowsList) { //Find the row handle matching the value. var rowHandle = FindRowHandleByKeyValue(view, value); //If no details ViewState exist for this value. if (!DetailViews.TryGetValue(value, out var state)) { //Expand the master row. view.SetMasterRowExpanded(rowHandle, true); } else { //Expand the master row and make the specified relation index the visible detail. view.SetMasterRowExpandedEx(rowHandle, view.GetRelationIndex(rowHandle, state._descriptor.LevelName), true); //Get the visible details view for the row. //If a details view is found then load the state for this details view. if (view.GetVisibleDetailView(rowHandle) is GridView detail) { state.RestoreState(detail); } } } //} //finally //{ // view.EndUpdate(); //} }
public ActionResult Create(DetailViews view) { if (ModelState.IsValid) { var pic = string.Empty; var folder = "~/Content/Image"; if (view.ImageFile != null) { pic = FileHelper.uploadphoto(view.ImageFile, folder); pic = string.Format("{0}/{1}", folder, pic); } var detail = ToDetail(view); detail.Image = pic; db.Details.Add(detail); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(view)); }
/// <summary> /// Stores the expanded master rows. /// </summary> /// <param name="view">The grid view to store expanded master rows for.</param> public void StoreExpandedMasterRows(GridView view) { //If there are no master details in the grid control then return to caller. if (view.GridControl.Views.Count == 1) { return; } //Clear any previously stored detail views. DetailViews.Clear(); //Clear any previously saved rows. SavedExpandedMasterRowsList.Clear(); //Go through each row in the grid view. for (var index = 0; index < view.DataRowCount; index++) { //Is the master row is expanded? if (view.GetMasterRowExpanded(index)) { //Get the key value of the row and add it to the expanded master rows list. var keyValue = view.GetRowCellValue(index, _descriptor.KeyColumn); SavedExpandedMasterRowsList.Add(keyValue); //Try and get the visible details view of the grid view. if (view.GetVisibleDetailView(index) is GridView detail) { //Create a new view state for the details view. var state = Create(this, detail); if (state != null) { //Save the state with it's key value. DetailViews[keyValue] = state; //Store the state of the details view. state.StoreState(detail); } } } } }