Skip to content

Data filtering .Net Grid

mary coroline

Asked May 30, 2016, 8:55 AM EDT1 answer
Share
LinkedInX

how can I create the filter itself and to set filtering conditions using already described IFilter interface. I am using Dapfor .Net grid.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    a brilliant question!. The following code should be of help.

    C#
    public class RatingEditor : UITypeEditorEx
    {
     public overridebool GetPaintCellSupported()
     {
     //The cellshould be repainted in the editor
     return true;
     }
    
     public overridevoid PaintCell(PaintCellEventArgs e)
     {
     //Do basicpainting without text
     e.Text =string.Empty;
     e.PaintAll();
     e.Handled =true;
    
     //Draw thestars over the cell
     Rectanglebounds = e.Cell.VirtualBounds;
     bounds.Width =Resources.star_grey.Width;
     for (int i = 0;i < 5; i++)
     {
     //Selectimage
     if (e.Cell.Value!= null && e.Cell.Value is int)
     {
     intcurRating = (int) e.Cell.Value;
     Imageimage = i >= curRating ? Resources.star_grey : Resources.star_yellow;
    e.Graphics.DrawImage(image, bounds);
    bounds.X += bounds.Width;
     }
     }
     }
    
     public overrideStopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReasonreason)
     {
     //Edit the cellif the user has clicked on the cell with the left button
     if (cell.Row !=null && Equals(StartEditReason.LButtonClick, reason))
     {
     Point pt =cell.Row.Grid.PointToClient(Cursor.Position);
     Rectanglebounds = cell.VirtualBounds;
    
     intimageWidth = Resources.star_grey.Width;
     if(bounds.Contains(pt) && imageWidth > 0)
     {
     //Set anew rating to the data object
    cell.Value = ((pt.X - bounds.X)/imageWidth) + 1;
    cell.Invalidate();
     }
     }
    
     returnStopEditReason.UserStop;
     }
    }
    0