I have a gridView with a 1to1 master-detail relationship for each master row. When a user clicks on the detail view I want to make sure that the master row is also activated (has the activated icon in the very left column):
This works fine if I navigate the master and detail grids with the keyboard, but doesn't work with the mouse. So I wrote to following code to try and fix this, but it doesn't work. This code is triggered via the detail view's click event:
GridView focusedView = gridView3.GridControl.FocusedView as GridView;
// get the currently selected row in the child view
int focusedRowHandle = focusedView.FocusedRowHandle;
// get the parentView's row handle that owns the child view
int sourceRowHandle = focusedView.SourceRowHandle;
GridView parentView = focusedView.ParentView as GridView;
parentView.BeginSelection();
parentView.SelectRow(sourceRowHandle);
parentView.EndSelection();
Can anyone let me know what I am doing wrong?
Are you using the Single Row selection mode? If multiple selection is disabled (the ColumnViewOptionsSelection.MultiSelect option is set to false) the SelectRow method does nothing.
Use the ColumnView.FocusedRowHandle property to select the master row that owns the detail View.
Related article: Selection Overview
Related
I use Blazorise DataGrid component to show my master/detail data in which you click master row and DataGrid shows detail row/rows.
How can one use the feature of RowDoubleClicked and change the natural behavior of DataGrid, to show detail row/rows when the event fires?
Visibility of detail row is handled by DetailRowTrigger. In the Blazorise demo for simplicity it is triggered only on selected row change, eg.
<DataGrid TItem="Employee"
#bind-SelectedRow="#selectedEmployee"
DetailRowTrigger="#((item)=>item.Id == selectedEmployee?.Id)">
To modify it to work with double click, you need to use DetailRowTrigger and save the selected id or item to a field so you can check for it within DetailRowTrigger handler.
<DataGrid TItem="Employee"
RowDoubleClicked="#(e=>selectedIdOnDoubleClick = e.Item.Id)"
DetailRowTrigger="#((item)=>item.Id == selectedEmployee?.Id)">
#code{
private int selectedIdOnDoubleClick ;
}
I'm using telerik grid view and i want to get the first element
when user selects a child's row (there migh be some recordes or rows)
I have this but it get's the first one anyway
radGridView1.Rows[0].ChildRows[0].Cells[0].Value
How can i get the first cell that user selects?
When a user selects a row in RadGridView - no matter if it is master or child row, this row can be accessed via the CurrentRow property:
radGridView1.CurrentRow.Cells[0].Value
You can also check out this article: link
I have a webform that the user captures data. This data affects other data that is in a Gridview. I wanted to right a DetailsView type control that makes an Update button visible if data is change in textboxes and drop downs that would require a master data update.
I have a gridview on the form and when the user click on update I wanted to update all the rows in the databases using the primary key OrderId which is on the Gridview.
If I put the code being each textbox and dropdown box and that calls a routine called DoUpdate then this works. However it is a little slow since each change forces an update, so I thought it would be better to rather have an update button appear, and then the user can click that to do the update.
When the routine is called from the button routine though the gridview has no rows. I assume I either need to findcontrol (gridview) or something but have not idea what to find it in.
Here is the code that works when called in a behind button event, but the gridview returns row count 0 when called as part of the code behind button:
List<string> _OrderIds = new List<string>();
foreach (GridViewRow gvr in gvOrderLines.Rows)
{
Label myOrderIDLablel = (Label)gvr.FindControl("lblOrderID"); //find control since it is a template field
_OrderIds.Add(myOrderIDLablel.Text);
}
The gridview is defined in the ASP page
<asp:GridView ID="gvOrderLines" runat="server" AutoGenerateColumns="False"
DataSourceID="odsOrderDetail"
Per my comment above you may want to do something like:
List<string> _OrderIds = new List<string>();
DataTable table = gvOrderLines.DataSource as DataTable;
foreach (GridViewRow gvr in table.Rows)
{
Label myOrderIDLablel = (Label)gvr.FindControl("lblOrderID"); //find control since it is a template field
_OrderIds.Add(myOrderIDLablel.Text);
}
I hope this get you headed in the right direction.
I realize that the DevExpress GridLookUpEdit editor was not designed to work with data that has multi-part keys. However, I am trying to workaround this limitation anyway.
The data for my GridLookUpEdit is Product-Purity with two columns "PRODUCT_ID" and "PURITY_ID". I have this code to set the purity of the underlying grid when the user selects the product-purity row in the GridLookupEdit:
void lookUpEditProductPurities_EditValueChanged(object sender, EventArgs e)
{
// Get the purity from the product selected and update the purity column of the grid.
DevExpress.XtraEditors.GridLookUpEdit editor = (sender as DevExpress.XtraEditors.GridLookUpEdit);
DevExpress.XtraGrid.Views.Grid.GridView view = editor.Properties.View as DevExpress.XtraGrid.Views.Grid.GridView;
object val = view.GetRowCellValue(view.FocusedRowHandle, "PURITY_ID");
if (editor.Parent is GridControl)
{
GridControl ParentGridControl = (editor.Parent as GridControl);
GridView ParentGridView = (ParentGridControl.MainView as GridView);
DataRow CurrentDataRow = ParentGridView.GetDataRow(ParentGridView.FocusedRowHandle);
CurrentDataRow["PRODUCT_PURITY_ID"] = val;
}
}
This works fine when I use it from a master grid, with one small problem. When an existing row refers to a purity that is not the first purity for a product, popping the grid will make it appear as though the first purity is selected. This is not a big deal as far as I am concerned.
However: the big problem I am having is when I use this GridLookUpEdit in a detail row of a master-detail grid. The call: editor.Parent is returning the grid control for the master and ParentGridControl.MainView is returning the GridView for the master.
How do I get at the gridView that the GridLookUpEdit is an editor for - the child gridView??
tia -
Your task (getting a detail view) can be implemented using the approach shown in the What can cause the properties, methods, and events of a detail grid view to fail? article - use the
GridView.GetDetailView method.
Please also review the following article:
Navigating Through Master and Detail Rows
I have been given a mockup that I do not know is possible to code in ASP.NET without being a real html and javascript wizard.
I want a GridView that when a row is selected, the selected row expands and below the selected row a panel of additional information is shown, which would also include another small GridView. The idea is this would all be in-line. So if the user selected row 4, then the additional information would appear below row 4 and then after the additional information the parent GridView would continue with row 5.
Ultimately I would want to do a multi-select type of set up, but first I need to figure out if this is even possible. Also, the solution must be 508 Compliant
The one solution I considered was using only one "column". Then I would put all my fields in the ItemTemplate, and my detail panel content in the EditItemTemplate and instead of selecting the row, set it to edit mode. The problem with this solution is I lose the functionality of multiple columns if I throw everything in one huge ItemTemplate.
Any and all suggestions or ideas are appreciated.
What you're describing would be best fulfilled with a ListView control. It takes a little more templating work to set up than a grid view, but you have much more control over it and you can emulate the look of a GridView. You would set your Selected Item template to contain another ListView (or GridView) thats bound to your detailed data.
I've done this using a gridview inside a ListView and using ajaxcontroltoolkit collapsible panel
Your parent list would be a listview that would have 2 table rows for each item, on the first row your parent column, on the second row use colspan and add a gridview wrapped on a collapsible panel