Krypton-OutlookGrid
Krypton-OutlookGrid copied to clipboard
GridView Filter
Hi
Great Job, Please it will be great to see a possibility of filtering that grid.
I'm trying to add filter support using Advanced GridView (https://github.com/davidegironi/advanceddatagridview) but it is not working.
any updates 👍 ?
Hi all
Yes, any updates about this?
Thanks 👍
Anyone on this? Thanks!
Hi, I know that it's a very old topic but I've managed to add Advanced GridView capabilities to the OutlookGrid. I've used a rude approach, by filtering using the filterstring updated from Advanced GridView control.
Outlookgrid has to inherit from "Advanced GridView" and the datasource has to be a DataTable and passed twice:
//get datasource
DataTable books = new DataTable();
books.ReadXml(Application.StartupPath + @"\Data\Books.xml");
OutlookGrid1.DataSource = books;
OutlookGrid1.BaseDataTable = books;
in the constructor of the Outlookgrid I've added a property and an event listner:
new property:
public object BaseDataTable { get; set; }
in constructor add:
this.FilterStringChanged += ModernOutlookGrid_FilterStringChanged;
and the sub:
bool blurredFilter = false;
private void ModernOutlookGrid_FilterStringChanged(object sender, FilterEventArgs e)
{
//Debug.WriteLine(this.FullFilterString);
if ((!string.IsNullOrEmpty(FullFilterString) && BaseDataTable != null) || blurredFilter)
{
//ClearEverything();
dataSource.Rows.Clear();
Rows.Clear();
DataView dvWorking = ((DataTable)BaseDataTable).DefaultView;
dvWorking.RowFilter = FullFilterString;
foreach (DataRow r in dvWorking.ToTable().Rows)
{
OutlookGridRow row = new OutlookGridRow();
//create row structure
row.CreateCells(this);
//populate cells
for (int i = 0; i < Columns.Count; i++)
{
row.Cells[i].Value = r[i].ToString();
}
dataSource.Rows.Add(row);
}
Fill();
blurredFilter = true;
}
}
in the "Advanced GridView" control I've added this property:
private string fullFilterString = string.Empty;
public string FullFilterString
{
get { return fullFilterString; }
}
and modified the funcion BuildFilterString() in this way:
#region " Filter Events "
/// <summary>
/// Build the complete Filter string
/// </summary>
/// <returns></returns>
private string BuildFilterString()
{
StringBuilder sb = new StringBuilder("");
String sbExt = "";
string appx = "";
foreach (string filterOrder in filterOrderList)
{
DataGridViewColumn Column = Columns[filterOrder];
if (Column != null)
{
ColumnHeaderCell cell = Column.HeaderCell as ColumnHeaderCell;
if (cell != null)
{
if (cell.FilterAndSortEnabled && cell.ActiveFilterType != MenuStrip.FilterType.None)
{
sb.AppendFormat(appx + "(" + cell.FilterString + ")", Column.DataPropertyName);
sbExt = sbExt + appx + ("(" + cell.FilterString + ")").Replace("{0}", Column.HeaderText).Replace("Convert([", "").Replace("],System.String)", "");
appx = " AND ";
}
}
}
}
fullFilterString = sbExt;
return sb.ToString();
}
As I said, It was rude and for sure not elegant, but it's ok for my needs..
Hope this helps
Angelo
with the same approach (using the sortstring) I've integrated the sort too... and fixed the filter for dates Angelo