Export Pivot Grid as Grid View to Excel - c#

So this may seem weird, but here is the situation I am currently dealing with. The goal is to take data from a Pivot Grid and put it into a Grid View, then export that Grid View to Excel.
Currently there is a working version to build a Grid View out of the data pulled from the Pivot Grid, however, I lose the formatting that the Pivot Grid had when I build the Grid View. My question is how would I capture that formatting out of the Pivot Grid, and how would I add it back into the Grid View?

I found a solution. Here it is below.
gridSettings.SettingsExport.RenderBrick = (sender, e) =>
{
foreach (MVCxPivotGridField item in dataFields)
{
if (e.RowType == DevExpress.Web.ASPxGridView.GridViewRowType.Data
&& !string.IsNullOrEmpty(item.CellFormat.FormatString))
e.TextValueFormatString = item.CellFormat.FormatString;
}
Grid Settings was my grid, and dataFields was the data from the Pivot Grid. I just looped through the data and found where there was a format string for the Pivot Grid and then set the same format to the Grid View.
};

Related

Remove or hide summary row in grouped row of telerik winform gridview

I have Telerik WinForm grid view that has several rows. I used summary row that calculate sum of column for me. I used grouping in Telerik WinForm grid view. I just want have one summary row at bottom of grid view not in all grouped rows.

Add new row at the top of grid without using row indicator

I have a button. When I click at it, a new row is added to the gridview and allow a user to edit in that row. How do I make new row appear in the first row?
It looks like the top most row in the following article but not
https://documentation.devexpress.com/#windowsforms/CustomDocument778
Currently, I did like the following code. It works but not good. With this solution, I also have a problem with scroll bar. If grid has many rows, the scroll bar will appear. Grid view will have a little blink when a new row is added because
it moves focus and scroll to last row -> last row is removed -> new row is added at the top -> move focus and scroll to top row
To disable scroll, I followed the article https://www.devexpress.com/Support/Center/Question/Details/CQ19190 to create a custom gridview. So far so good. But the problem is I do not want to custom grid. Does anybody have idea?
If I have to custom grid, how can I convert MainView to my custom grid at design mode?
- in design mode, click on MainView of grid view, then choose convert to ...-> custom grid view does not appear in the menu
Sample code
private void AddNewRow(GridView gv) {
gv.AddNewRow();
var row = gv.GetRow(GridControl.NewItemRowHandle);
var helper = new ListDataControllerHelper(gv.DataController);
// Binding list has a method InserAt(index, object), but in my case the object can not be created directly.
// Hence, I do not know what it is. I only get new object through gv.AddNewRow()
// I can work around by extending binding list
// but grid view does not support adding new row at specific position to adapt with InsertAt or my custom binding list
// It is not a good idea
helper.BindingList.Remove(row);
helper.BindingList.Insert(0, row);
gv.FocusedRowHandle = 0;
gv.SetFocusedRowModified();
}
I will appreciate all the help.
Thank you
If you simply want to add a row without your layout being updated automatically, try to suspend and resume the layout like so:
gv.SuspendLayout();
helper.BindingList.Remove(row);
helper.BindingList.Insert(0, row);
gv.FocusedRowHandle = 0;
gv.SetFocusedRowModified();
gv.ResumeLayout(true);
In general, your method of inserting a row seems fine.

How to make custom header with data grid in WPF?

I want to make data grid with custom header. My header contains of Row Span and Column Span. So I have decided using grid as the layout and then datagrid as my control data.
You can see my header like this..
and then below that header I wanna make datagrid how I can do it? I'm still newbie in WPF and then how I can make the column in my grid layout can match datagrid that I have created below that?

Printing only selected columns of Gridview

I am trying to print contents of grid view control. But I want to skip few columns from printing. Print functionality is working fine, but how to skip few columns of grid view from printing.
Below is my code:
PrintHelper.PrintWebControl(grdAppointments );
grdAppointments is name of grid view control. It prints all columns of grid, but I want to print only few columns.
When printing the page-
1) First hide the unwanted columns
2) Then call the print() function
3) Show previously hided columns
You can refer following link to hide the columns
Hide GridView column using javascript
A non-programmatical solution could be that you create a temporary grid and copy all selected columns/items to it, and print that gridview data. Then dispose it.
To get selected columns:
if (dataGridView1.SelectedColumns.Count > 0)
{
foreach (DataGridViewColumn c in dataGridView1.SelectedColumns)
dataGridView2.Columns.Add(c);
}

GridLookUpEdit and Multi-part Keys

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

Categories

Resources