Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
WinGrid + Image Column filtering
posted

Hi all,

We use Infragistics 10.3 and cannot move to other version.

We have an UltraGrid and a column with images. I need to filter records by this column. Picture 1 shows what I have.

If I expand ValueList for this column, I see useless lines "System.Drawing.Bitmap" (see picture 2)

1. I want to see "good names" for all images.

To resolve this issue, I've added special class BitmapFilterCondition : FilterCondition, IConvertible with overridden method MeetsCriteria and changed filling of ValueList within BeforeRowFilterDropDownPopulate event. The result is at the picture 3.

But the next problems are:

2. the selected picture is doubled in the FilterRow. I expect to see "=" sign at the left side of filtered cell (see picture 4).

3. Also when I go out of filter and select any other cell, the value in FilterCell shows "System.Drawing.Bitmap" text instead of correct text (see picture 5).

4. Also when I click "Clear All Filters" button, the exception appears (see picture 6).

The source code of my example project is attached.

Can anybody help me to resolve all these issues or even better provide me example of really working code?

Thanks.

 

 

PS. Forum doesn't work properly (doesn't allow me to attach the source code).

There is the source:

        private Bitmap create_ = new Bitmap(Resources.CreateView16);
        private Bitmap delete_ = new Bitmap(Resources.DeleteView16);
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            Infragistics.Win.UltraWinGrid.UltraGridBand ultraGridBand1 = new Infragistics.Win.UltraWinGrid.UltraGridBand("Band 0", -1);
            Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn3 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("Column 0");
            Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn4 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("Column 1");
            Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn1 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("Column 0");
            Infragistics.Win.UltraWinDataSource.UltraDataColumn ultraDataColumn2 = new Infragistics.Win.UltraWinDataSource.UltraDataColumn("Column 1");
            this.ultraGrid1 = new Infragistics.Win.UltraWinGrid.UltraGrid();
            this.ultraDataSource1 = new Infragistics.Win.UltraWinDataSource.UltraDataSource(this.components);
            this.panel1 = new System.Windows.Forms.Panel();
            ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.ultraDataSource1)).BeginInit();
            this.SuspendLayout();
            // 
            // ultraGrid1
            // 
            this.ultraGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.ultraGrid1.Cursor = System.Windows.Forms.Cursors.Default;
            this.ultraGrid1.DataSource = this.ultraDataSource1;
            ultraGridColumn3.Header.VisiblePosition = 0;
            ultraGridColumn4.Header.VisiblePosition = 1;
            ultraGridBand1.Columns.AddRange(new object[] {
            ultraGridColumn3,
            ultraGridColumn4});
            this.ultraGrid1.DisplayLayout.BandsSerializer.Add(ultraGridBand1);
            this.ultraGrid1.DisplayLayout.Override.FilterClearButtonLocation = Infragistics.Win.UltraWinGrid.FilterClearButtonLocation.Row;
            this.ultraGrid1.DisplayLayout.Override.FilterUIType = Infragistics.Win.UltraWinGrid.FilterUIType.FilterRow;
            this.ultraGrid1.Location = new System.Drawing.Point(8, 8);
            this.ultraGrid1.Name = "ultraGrid1";
            this.ultraGrid1.Size = new System.Drawing.Size(447, 240);
            this.ultraGrid1.TabIndex = 1;
            this.ultraGrid1.Text = "UltraGrid1";
            // 
            // ultraDataSource1
            // 
            ultraDataColumn1.DataType = typeof(object);
            this.ultraDataSource1.Band.Columns.AddRange(new object[] {
            ultraDataColumn1,
            ultraDataColumn2});
            // 
            // panel1
            // 
            this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.panel1.Location = new System.Drawing.Point(8, 256);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(447, 32);
            this.panel1.TabIndex = 2;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(463, 294);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.ultraGrid1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1Load);
            ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.ultraDataSource1)).EndInit();
            this.ResumeLayout(false);
 
        }


        private void Form1Load(object sender, EventArgs e)         {             var row = ultraDataSource1.Rows.Add();             row[0] = create_;             row[1] = "First";             row = ultraDataSource1.Rows.Add();             row[0] = delete_;             row[1] = "Second";             row = ultraDataSource1.Rows.Add();             row[0] = delete_;             row[1] = "Third";             ultraGrid1.DisplayLayout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;             SetImageColumnAppearence(ultraGrid1, 0);         }         public void SetImageColumnAppearence(UltraGrid grid, int index)         {             var editedColumn = grid.DisplayLayout.Bands[0].Columns[index];             editedColumn.FilterOperandStyle = FilterOperandStyle.DropDownList;             editedColumn.FilterOperatorAppearance.ImageHAlign = HAlign.Left;             editedColumn.CellAppearance.ImageHAlign = HAlign.Center;             editedColumn.FilterOperatorDefaultValue = FilterOperatorDefaultValue.Equals;             grid.BeforeRowFilterDropDownPopulate += delegate(object sender, BeforeRowFilterDropDownPopulateEventArgs e)                 {                     if (e.Column.Index != index)                         return;                     var bmps = GetAllRowsFilterItems(grid, e).Distinct().ToList();                     foreach (var bitmap in bmps)                     {                         var item = e.ValueList.ValueListItems.Add( new BitmapFilterCondition(bitmap, GetCaption(bitmap)));                         item.Appearance.Image = bitmap;                     }                     e.Handled = true;                 };             grid.FilterCellValueChanged += delegate(object sender, FilterCellValueChangedEventArgs e)                                                {                                                    if (e.FilterCell.Column.Index != index)                                                        return;                                                    var editor = e.FilterCell.EditorResolved;                                                    var bitmap = editor.IsValid                                                                     ? editor.Value as BitmapFilterCondition                                                                     : null;                                                    e.FilterCell.Appearance.ImageHAlign = HAlign.Left;                                                    e.FilterCell.Appearance.Image = bitmap != null                                                                                        ? bitmap.ToType(typeof (Bitmap), null)                                                                                        : null;                                                    e.FilterCell.Appearance.TextHAlign = HAlign.Left;                                                    //e.FilterCell.Value = bitmap;                                                };         }         private string GetCaption(Bitmap bitmap)         {             if (bitmap == create_)                 return "Create";             if (bitmap == delete_)                 return "Delete";             return string.Empty;         }         private static IEnumerable<Bitmap> GetAllRowsFilterItems(UltraGridBase grid,                                                                  BeforeRowFilterDropDownPopulateEventArgs e)         {             var bitmaps = new List<Bitmap>();             var rows = (e.Rows as IEnumerable<UltraGridRow>) ??                        grid.Rows.GetAllNonGroupByRows();             foreach (var row in rows)             {                 if (row.Hidden)                     continue;                 var bitmap = row.Cells[e.Column].Value as Bitmap;                 if (bitmap == null)                     continue;                 bitmaps.Add(bitmap);             }             return bitmaps;         }     }     internal class BitmapFilterCondition : FilterConditionIConvertible     {         #region Private Fields         private readonly Image bitmap_;         private readonly string caption_;         #endregion // Private Fields         #region Constructors/Destructors         public BitmapFilterCondition(Image bitmap, string caption)             : base(FilterComparisionOperator.Equals, bitmap)         {             bitmap_ = bitmap;             caption_ = caption;             //ComparisionOperator = FilterComparisionOperator.Equals;             //CompareValue = bitmap_;         }         #endregion // Constructors/Destructors         #region Public Methods         public override bool MeetsCriteria(UltraGridRow row)         {             return bitmap_ == row.Cells[Column.Key].Value as Bitmap;         }         public override string ToString()         {             return caption_;         }         #endregion // Public Methods         #region IConvertible Members         public TypeCode GetTypeCode()         {             return TypeCode.Object;         }         public bool ToBoolean(IFormatProvider provider)         {             throw new NotImplementedException();         }         public char ToChar(IFormatProvider provider)         {             throw new NotImplementedException();         }         public sbyte ToSByte(IFormatProvider provider)         {             throw new NotImplementedException();         }         public byte ToByte(IFormatProvider provider)         {             throw new NotImplementedException();         }         public short ToInt16(IFormatProvider provider)         {             throw new NotImplementedException();         }         public ushort ToUInt16(IFormatProvider provider)         {             throw new NotImplementedException();         }         public int ToInt32(IFormatProvider provider)         {             throw new NotImplementedException();         }         public uint ToUInt32(IFormatProvider provider)         {             throw new NotImplementedException();         }         public long ToInt64(IFormatProvider provider)         {             throw new NotImplementedException();         }         public ulong ToUInt64(IFormatProvider provider)         {             throw new NotImplementedException();         }         public float ToSingle(IFormatProvider provider)         {             throw new NotImplementedException();         }         public double ToDouble(IFormatProvider provider)         {             throw new NotImplementedException();         }         public decimal ToDecimal(IFormatProvider provider)         {             throw new NotImplementedException();         }         public DateTime ToDateTime(IFormatProvider provider)         {             throw new NotImplementedException();         }         public string ToString(IFormatProvider provider)         {             return caption_;         }         public object ToType(Type conversionType, IFormatProvider provider)         {             if (conversionType.IsAssignableFrom(bitmap_.GetType()))                 return bitmap_;             return null;         }         #endregion     }
Parents Reply Children