GridLookUpEdit and Multi-part Keys - c#

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

Related

Asp.Net C# Dynamic GridView Options and Values on Sorting

I have a GridView Control that displays data from a table on Page_Load as well as a progress bar in one column and a button in another.
It then loops through each row of the Table and depending on the values, hides said button (i.e. if the 1st column value = "Open" then the button in the 8th column is hidden). It uses a simple foreach loop;
foreach (GridViewRow Row in MyGridView.Rows)
{
if(Row.Cells[0].Text == "Open")
{
Row.Cells[7].Text = "";
}
}
This is working absolutely fine on page load... unfortunately once the user sorts the data by the column values it doesn't work. I can get the event to fire (testing between OnSort and OnSorting amongst other events on the board) but it isn't actually making any changes to the table.
It seems the issues lays somewhere in how I'm attempting to initiate it... does anyone have any ideas?
Thanks in advance.
Managed to work this out through more testing. For anyone with a similar problem, use the DataGridViews OnPreRender Event.

gridview can't get the last row from the gridview

I have an c sharp desktop application the user wants me to make the same into a web application, i have a datagrid on the desktop application and added a gridview on my webform.
Also have a button named last record when clicked returns the last row of the data grid view:
net_Weight_TrackingDataGridView.FirstDisplayedScrollingRowIndex = net_Weight_TrackingDataGridView.RowCount - 1;
I am trying to get the same functionality to work in grid view:
my grid view has these turned on:
this.GridView1.AllowPaging = true;
this.GridView1.AllowSorting = true;
because i have a lot of data and if i set the above to false the page keeps loading and loading.
for the last row i tried:
GridViewRow LastRow = GridView1.Rows[GridView1.Rows.Count - 1];
The above piece of code is not working....
Any help will be generously appreciated.
From MSDN:
If the GridView control is bound to a data source control that is
capable of returning a single page of data when requested, the
GridView control will take advantage of that capability directly.
If the GridView control is bound to a data source control that does
not support the paging capability directly, or if the GridView control
is bound to a data structure in code through the DataSource property,
the GridView control will perform paging by getting all of the data
records from the source, displaying only the records for the current
page, and discarding the rest.
So,
this.GridView1.AllowPaging = true;
this.GridView1.AllowSorting = true;
work only if you have case #1. If you have case #2, asp.net will request all data and this is why your page is slow. To avoid this situation you either need to use data source control as per case #1 or even better implement custom paging so that your query does not return all rows from the database, but only X required rows.
Read about custom paging (example)

DevExpress XtraGrid - Cannot select Master Row

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

Datagrid on demand load off

I have a SDK:DATAGRID with 20 columns or so, when it opens up it only shows four fields/columns. Which is what I want and how I designed it
Basically I'm grabbing information based on the user click - EXAMPLE:
OWNERNAME.Text = ((TextBlock)EPICGrid.Columns[1].GetCellContent(EPICGrid.SelectedItem)).Text;
and/or
OWNERNAME2.Text = ((TextBlock)EPICGrid.Columns[16].GetCellContent(EPICGrid.SelectedItem)).Text;
What I'm running into it doesn't grab the information in the cell unless if I scroll and show the column so I can only grab the first 4 columns of data because they show when the grid becomes visible.
I can't grab data from columns 5 -20 unless I scoll over and make those columns visible. They don't have to be visible during the click...it just seems like the data doesn't really load until I view the column.
I guess I should say the first record/row loads all the data/cells/columns and I can grab any data from the first record but the problem happens with records 2 - *.
Just to clarify - my issue is not a visibility of my columns or rows. My issue is the SDK DataGrid seems like it is loading the data on demand. So if the column is not in view at one point or another the information in the cell is not available.
I don't want to show all columns and I don't want to give the user the ability to see all columns so I want to disable the scroll bars but when a user clicks on a certain row I need to grab information in certain cells and since the column is not load yet the information is not there.
How do I turn the feature load on demand off?
I did a search and found out that someone had a similar problem with rows loading and the suggestion was setting the VirtualizingStackPanel.VirtualizationMode = Standard
It almost like the problem is stemmed from VirtualizingStackPanel.VirtualizationMode but I set this property to standard and recycle and no luck.
Here's definition:
By default, a VirtualizingStackPanel creates an item container for
each visible item and discards it when it is no longer needed (such as
when the item is scrolled out of view). When an ItemsControl contains
a lot of items, the process of creating and discarding item containers
can negatively affect performance. When
VirtualizingStackPanel.VirtualizationMode is set to Recycling, the
VirtualizingStackPanel reuses item containers instead of creating a
new one each time.
On initial load, if the cell is not visible I can not grab the cells
content (unless it is the first record/row). Once and after the cell /
column is visible then the information is available.
I think you are expected to deal with the data that the row is bound to directly and not pull the data out of the controls. This makes sense since it is two way data binding so the data is updated as you are changing it (assuming it implements the INotifyPropertyChanged Interface).
An example would be where a datagrid is bound to a collection of type MyEntity.
private void DataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.DataGrid1.SelectedItem == null)
return;
MyEntity myEntity = (MyEntity)this.DataGrid1.SelectedItem;
// at this point you have the (updated) data the row is bound to.
MessageBox.Show("You Selected: " + myEntity.name);
...
Another example is where there is a button on each row. The code to process when a button is clicked looks something like:
private void btnProcessEntity_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
MyEntity myEntity = btn.DataContext as MyEntity;
// clicking a button in a row doesn't select the row, so select it.
this.DataGrid1.SelectedItem = myEntity;
MessageBox.Show("Will Process: " + myEntity.name);
...
}
If you are not familiar with some of the technologies that normally are used with Silverlight check out these Video Tutorials. It is VB.Net, but the code is really not the focus - it is focused on a Silverlight application architecture. I would start with "Intro to SL4 and WCF Ria Services" and then view one of the ones on MVVM.

Dynamically Add TemplateField to Details View

I have a grid view that, on selected index, will populate a details view. If the selected index happens to have multiple IP Address's I want to add additional fields to display them. They don't need to be databound since I know the data. I'm using the code below to create the additional template fields. This is done in the Data Binding event.
This works until I select a different row in the grid view, then no data is displayed in the details view. My theory is that it's trying to bind the data but there are a different amount of values returned from the database than controls to put them in. I guess is there an easier way to do this?
// Check for multiple IP
countIP = devicesDetails_CountIP(devicesDataKey);
if (countIP > 1)
{
TemplateField IPAddress2 = new TemplateField();
devicesDetailsView.Fields.Insert(0, IPAddress2);
}
Recently I came across this question, so here is a link that may be of help for future visitors
Create DetailsView from codebehind

Categories

Resources