I'm developing a web page witch has an AspxTreelist and an ASPxGridView. I would like to fill the grid with data after selecting some nodes on treelist. The treelist nodes are filtering the grid data
Here is my code samples :
Here I'm getting the selected nodes
Categories = new List<int>();
foreach (TreeListNode node in categs)
{
Categories.Add(int.Parse(node["Key"].ToString()));
}
And here I'm filling the grid
if (Categories!= null && Categories.Count > 0)
{
DGEmails.DataSource = Manager.GetBySubTree(Categories);
DGEmails.DataBind();
}
The problem is that after I get the Categories and fill the Grid's datasource (these parts work fine) there are not any data displaying on the grid.
I figured out the problem, it was the fact that treelist by default uses callbacks and I had to disable them.
Related
I'm facing issue in binding single row to the treelist. In my application I have a two forms. first form contains treelist it will contain list of rows.
I need a selected row from the list. Using
public object selectedRow
{
return treelist.GetDataRecordByNode(treelist.FocusedNode)
}
using this code I get the selected row.
In second Form, I'm trying to bind that row.
public void row(selectedRow)
{
treelist2.DataSource=selectedRow; //I get the row value here.
}
But data not able to shown in second treelist. what step I need to do to bind a selectedrow to second treelist.
the DataSource should be an IEnumerable-type.
try something like this (pseudo-code ahead):
public void row(selectedRow)
{
List<yourType> list = new List<yourType>();
list.Add(selectedRow);
treelist2.DataSource=list;
}
Please go through TreeList's Data Binding section, Data Binding topic provides the complete information on binding the TreeList to data.
You can find reference to bind it with class objects here -
Binding Controls to Data Created at Runtime
In your row method, you should either create a List<ClassType> or BindingList<ClassType> before assigning the data source property. A list of ClassType objects can be created and bound to a data-aware control as follows:
BindingList<ClassType> list = new BindingList<ClassType>();
treelist2.DataSource = list;
References:
DevExpress TreeList not displaying child nodes and displaying as root nodes instead
binding data to the treelist control
Binding data in DevExpress Treelist from database
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.
};
I'm using a DataGridView with bounded List of objects in my application. So I have:
grid.DataSource = Files.Instance.List;
in my form load event and than I want to have two buttons - for adding and removing items from the list (so also from the grid), I though it should be as simple as:
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Files.Instance.List.Add(new DelphiFile { FilePath = openFileDialog.FileName });
grid.Refresh();
}
I'm only setting up the start path here, I wanted the rest parameters to be set by user in the grid view.
The item is added correctly but unfortunatelly it doesnt appear on the list, why?
I also have issues with deleting items:
foreach(DataGridViewRow row in grid.SelectedRows)
{
Files.Instance.List.Remove(row.DataBoundItem as DelphiFile);
}
grid.Refresh();
items are deleted correctly but again the grid doesn't seem to refresh and I'm even getting an exception because the last item in the grid doesn't have a value than :O .
What am I doing wrong?
I guess you declared Files.Instance.List as of type List<DelphiFile>, so when the collection is changed, the dataGridView doesn't know about that, use BindingList<DelphiFile> instead.
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 an ASP .NET GridView with Paging. One column in it has a CheckBox. In a certain scenario, I want to uncheck the checkboxes that are checked.
foreach (GridViewRow dr in gvMyGridView.Rows)
{
if (dr.RowType == DataControlRowType.DataRow)
{
if ((CheckBox)dr.FindControl("chkIsApplicable") != null)
{
((CheckBox)dr.FindControl("chkIsApplicable")).Checked = false;
}
}
}
But unfortunately because of Paging only the records that are currently shown in the Grid can be accessed in this way. I want it to apply to ALL the items in the GridView. This should happen client side and when the user commits will get saved to the database. Any way to handle this? :)
Maintaining the State of Checkbox while Paging in Gridview
The Logic
Save the checked rows primary keys to a list at PageIndexChanging event.
After setting the grid to new PageIndex and re-binding the grid, populate the new page with values in the list that is mapped to the rows in grid(if any)
So you will have a collection of checked rows in a list.
Delete the list to clear all.
This is one way of doing it.
PS: Its a two year old post, so you can surely optimise it with C# 4.0