filtering contents of radgridview - filter

i have a problem with filtering th contents of my radgridview.
here's my code
private void Filter_Click(object sender, System.Windows.RoutedEventArgs e)
{
FilterDescriptor filter = new FilterDescriptor("Name", FilterOperator.Contains, (RadGridView1.SelectedItem as Person).Name);
RadGridView1.FilterDescriptors.Add(filter);
}
it only filters the "Name" column. i want it to filter the data based on the value of the cell clicked... i have to get the column name of the cell clicked and replace it to "Name" in my code...
can anyone help me with this?

here's the code to filter:
FilterDescriptor filter = new FilterDescriptor(RadGridView1.CurrentCell.Column.UniqueName, FilterOperator.IsEqualTo, RadGridView1.CurrentCell.Value);
RadGridView1.FilterDescriptors.Add(filter);
here's the code to remove filter:
RadGridView1.FilterDescriptors.Clear();
RadGridView1 is the name of the radgridview.

Related

Infragistics XamGrid: How to prevent column filter from showing time?

We are using DateTime columns with time, but need the (excel style distinct elements) column filter to show only the dates, without time. Is that possible?
I found an article at Infragistics which describes how to add a custom filter but not how to change an existing one.
Got the following code snipped from infragistics support (thanks Tacho!):
private void XamDataGrid_RecordFilterDropDownOpening(object sender, RecordFilterDropDownOpeningEventArgs e)
{
if (e.Field.DataType == typeof(DateTime))
{
List<FilterDropDownItem> cellValues = e.DropDownItems.Where(i => i.IsCellValue).ToList();
foreach (FilterDropDownItem item in cellValues)
e.DropDownItems.Remove(item);
foreach (FilterDropDownItem item in cellValues)
{
item.DisplayText = (item.Value as DateTime?).Value.ToString("yyyy/MM/dd");
if (!e.DropDownItems.Contains(e.DropDownItems.FirstOrDefault(i => i.DisplayText == item.DisplayText)))
{
var newItem = new FilterDropDownItem(new Infragistics.Windows.Controls.ComparisonCondition(
Infragistics.Windows.Controls.ComparisonOperator.Contains, item.DisplayText), item.DisplayText);
e.DropDownItems.Add(newItem);
}
}
}
}

How to get ItemIndex in Transferred event of Rad ListBox

I'm trying to get selected Item Text and value of RadListBox in Transferred event.
I tried following code:
protected void listbox_Initial_Transferred(object sender, RadListBoxTransferredEventArgs e)
{
string id = e.Items[0].Value.ToString();
string description = e.Items[0].Text.ToString();
}
here i passed "0" as index. Its working fine.
Now i got stuck here to fetch the selected index of Item.
Looking forward for your comments and replies.
Thanks.
Please try with the below code snippet.
// for single item
string id = RadListBox1.SelectedItem.Value.ToString();
string description = RadListBox1.SelectedItem.Text.ToString();
// for multiple item
foreach (RadListBoxItem item in RadListBox1.SelectedItems)
{
string _id = item.Value.ToString();
string _description = item.Text.ToString();
}
AS per your sample code, please also try with the below code snippet.
// for multiple item
foreach (RadListBoxItem item in e.Items)
{
string _id = item.Value.ToString();
string _description = item.Text.ToString();
}

ASPxGridView Group Summary Sorting - It sorts the content inside, not the summary outside

I have done grouping of the grid by giving groupindex to a particular column in aspxgridview.
For example, if I am grouping by means of persons name and the orders details made by that particular person would come in the detailed content when the arrow is clicked to view the content.
When I click on the header fields to sort, it is sorting the data inside the groupContent but it is not used for sorting the data of groupsummary
I am showing all the totals as a part of group summary besides the person's name.
For example if you see in the below link:
https://demos.devexpress.com/ASPxGridViewDemos/Summary/GroupSortBySummary.aspx
If you sort by company name, the content would be sorted, but the summary showing the country and sum has no means to get sorted at outside level.
Please do suggest me options to work out this problem.
Thanks.
Here is workaround, based on this example.
The main idea is to create summary item which shows the minimum or maximum value of Country column inside City group and sort City group by this summary values. For this BeforeColumnSortingGrouping event is used to change the sorting behavior.
Here is example:
<dx:ASPxGridView ...
OnBeforeColumnSortingGrouping="gridCustomers_BeforeColumnSortingGrouping">
private void SortByCountry()
{
gridCustomers.GroupSummary.Clear();
gridCustomers.GroupSummarySortInfo.Clear();
var sortOrder = gridCustomers.DataColumns["Country"].SortOrder;
SummaryItemType summaryType = SummaryItemType.None;
switch (sortOrder)
{
case ColumnSortOrder.None:
return;
break;
case ColumnSortOrder.Ascending:
summaryType = SummaryItemType.Min;
break;
case ColumnSortOrder.Descending:
summaryType = SummaryItemType.Max;
break;
}
var groupSummary = new ASPxSummaryItem("Country", summaryType);
gridCustomers.GroupSummary.Add(groupSummary);
var sortInfo = new ASPxGroupSummarySortInfo();
sortInfo.SortOrder = sortOrder;
sortInfo.SummaryItem = groupSummary;
sortInfo.GroupColumn = "City";
gridCustomers.GroupSummarySortInfo.AddRange(sortInfo);
}
protected void Page_Load(object sender, EventArgs e)
{
SortByCountry();
}
protected void gridCustomers_BeforeColumnSortingGrouping(object sender, ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
{
SortByCountry();
}
When you group by a column devexpress automatically uses that column to sort. Without sorting the data the grouping is not possible. To overcome this issue we have sorted the datasource itself then applied that datasource to the grid.

Why RadFilter is not detecting Columns correctly?

I am having trouble that RadFilter is not detecting the columns correctly. I bind my RadGrid through code in Asp like:
RadGrid1.DataSource = myDataSource;
RadGrid.DataBind();
RadFilter is only binding those columns which are bind through and ignoring those who are in . Is this a known issue? as I didn't see any thread talking about this problem. Waiting for help immediately.
Regards,
Wasim.
If I am understanding you correctly, you need to add FilterFieldEditors to the RadFilter for any field that is not represented in the DataSource for the grid.
You can add filters dynamically with the following code.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
var fieldName = "myDynamicFilterField";
var friendlyName = "Friendly Dynamic Field";
var newTextFieldEditor = new RadFilterTextFieldEditor();
filter.FieldEditors.Add(newTextFieldEditor);
newTextFieldEditor.FieldName = fieldName; // name filter will used for filter exressions
newTextFieldEditor.DisplayName = friendlyName; // name use will see when they selected a field to filter
// ** Repeat for all dynamic fields **
}
}
I was able to get a working version using auto generated columns and custom added columns, but ran into many other problems. I ended up just dynamically creating all the filter fields (as shown above) from the data source and applying the filter expression to the grid.

Value of Column Name DataGridView

I'm using Visual Studio 2010 and i'm developing a windows form. Right now I'm using a data grid view and i want to write some functions that would allow you to automaticlly edit the datagrid by just changing the text in the Datagrid view. Right now, I am able to get the actual value but I need the value of the column in order to use it as a parameter when i use ADO.net here's what my code looks like now
private void dgv_DataLookup_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DialogResult dr;
dr = MessageBox.Show("Are you sure you want to edit this field?", "Edit Cell", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
DataGridViewCell editItemCell = dgv_DataLookup[dgv_DataLookup.CurrentCell.RowIndex, dgv_DataLookup.CurrentCell.ColumnIndex];
string editItem = editItemCell.Value.ToString();
}
}
this here gets me the value of the current cell that is currently selected. I tried doing something like this
DataGridViewColumns columnCells = dgv_DataLookup.CurrentCell.ColumnIndex.Value.ToString()... something that would represent this but actual code. thanks!
According to what I understand you want to edit the value within a field, you can choose the value in this way.
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to edit this field?",Application.ProductName.ToString(),MessageBoxButtons.YesNo)== DialogResult.Yes)
{
string editItem = this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index].Cells["NameField"].Value.ToString();
}
}
Bye

Resources