When i filter on a range like “C1:D1” to “C4:D4”, autofilter applys on all the columns. I want just the selected columns to be filtered.
public void EditFilterSpecial()
{
try
{
if (gridDesktop1.Worksheets.Count <= 0) return;
Aspose.Cells.GridDesktop.Worksheet ws;
int ActShIndex = gridDesktop1.Worksheets[gridDesktop1.ActiveSheetIndex].Index;
ws = gridDesktop1.Worksheets[ActShIndex];
int StartRow = 0, StartColumn = 0, EndRow = 0, EndColumn = 0;
CellRange cr = ws.GetLastSelection();
if (cr == null)
{
GridCell gc = ws.GetFocusedCell();
StartRow = gc.Row;
StartColumn = gc.Column;
EndRow = ws.RowsCount;
EndColumn = gc.Column;
}
else
{
StartRow = cr.StartRow;
StartColumn = cr.StartColumn;
EndRow = cr.EndRow;
EndColumn = cr.EndColumn;
}
Aspose.Cells.GridDesktop.RowFilterSettings rf = ws.RowFilter;
Workbook workbook = new Workbook(m_xmlSSFilename);
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
if (!bfilter)
{
// Creating AutoFilter by giving the cells range of the heading row
m_cr.Copy(cr);
// ExEnd:1
rf.EnableAutoFilter = true;
worksheet.AutoFilter.SetRange(StartRow, StartColumn, EndColumn);
ws.AddAutoFilter(StartRow, StartColumn, EndColumn);
rf.HeaderRow = StartRow;
rf.StartRow = rf.HeaderRow;
rf.EndRow = EndRow;
bfilter = true;
worksheet.AutoFilter.Range = worksheet.AutoFilter.Range;
for (int i = 0; i < (EndColumn - StartColumn + 1); i++)
{
worksheet.AutoFilter.AddIconFilter(i, IconSetType.ArrowsGray3, 0);
string strButtonText = “”;
/if(ws.Cells.GetCell(StartRow, StartColumn + i).Value != null)
strButtonText = ws.Cells.GetCell(StartRow, StartColumn + i).Value.ToString();/
ws.Controls.AddButton(StartRow, StartColumn + i,
ws.Columns[StartColumn + i].Width, ws.Rows[StartRow].Height,
strButtonText, true);
Aspose.Cells.GridDesktop.Button bt = (Aspose.Cells.GridDesktop.Button)ws.Controls[StartRow, StartColumn + i];
CellControl cc = ws.Controls[StartRow, StartColumn + i];
bt.Image = getFilterImage();
}
worksheet.AutoFilter.Refresh();
}
else
{
StartRow = m_cr.StartRow;
StartColumn = m_cr.StartColumn;
EndRow = m_cr.EndRow;
EndColumn = m_cr.EndColumn;
for (int i = 0; i < (EndColumn - StartColumn + 1); i++)
{
ws.Controls.Remove(StartRow, StartColumn + i);
}
worksheet.AutoFilter.ShowAll();
worksheet.AutoFilter.Refresh();
rf.HeaderRow = -1;
rf.StartRow = -1;
rf.EndRow = -1;
rf.EnableAutoFilter = false;
ws.RemoveAutoFilter();
ws.UnFreezePanes();
bfilter = false;
worksheet.AutoFilter.Range = null;
worksheet.AutoFilter.Refresh();
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}