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
170
Weird paint behaviour on UltraWinGrid
posted

I have an ultrawingrid (v7.2) and I want to display custom default values to the user if a cell's value is null. The details of the calculation of the default value is not really important but I need to run some code every time the cell is being displayed to determine what to display, but crucially, I do not want to change the null value in the cell. It is simply for display purposes.

I have tried writing a datafilter which works up to a point. The main problem I have is that there are occasions where the datafilter doesnt appear to run correctly and I get spurious values being displayed or cells being displayed as empty. In particular if the user moves the mouse over other cells in the grid whilst a cell is in edit mode, cells are painted with weird display values.

My simplified code is as follows where my 'default value' is simply the column.key property. If you click to edit a cell then move the mouse around you get the weird behaviour.

Can you reproduce this. Is this a bug or am i doing something wrong?

Thanks

Andy

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Common;
using System.Data.Odbc;
using Infragistics.Win.UltraWinGrid;

namespace testgrid
{
    public partial class Form1 : Form
    {
        private string connectionString_ = "DSN=Autopricing;Pwd=pwd";

        private OdbcConnection connection_;

        public Form1()
        {
            InitializeComponent();

            connection_ = new OdbcConnection(connectionString_);
            DataTable table = loadSql("select * from value");
            ultraGrid1.DataSource = table;
            DataFilterCallback callback = new DataFilterCallback(grid_DataFilter);
            foreach (UltraGridColumn col in ultraGrid1.DisplayLayout.Bands[0].Columns)
                col.Editor.DataFilter = callback;
        }

        DataTable loadSql(string sql)
        {
            OdbcDataAdapter adapter = new OdbcDataAdapter(sql, connection_);
            DataTable table = new DataTable();
            adapter.Fill(table);
            return table;
        }
        class DataFilterCallback : Infragistics.Win.IEditorDataFilter
        {
            public delegate object Callback(Infragistics.Win.EditorDataFilterConvertArgs args);
            public DataFilterCallback(Callback callback)
            {
                callback_ = callback;
            }
            object Infragistics.Win.IEditorDataFilter.Convert(Infragistics.Win.EditorDataFilterConvertArgs args)
            {
                return callback_(args);
            }
            Callback callback_;
        }
        object grid_DataFilter(Infragistics.Win.EditorDataFilterConvertArgs args)
        {
            UltraGridCell cell = args.Context as UltraGridCell;

            if (cell != null)
            {
                if (args.Direction == Infragistics.Win.ConversionDirection.EditorToDisplay)
                {
                    if (args.Value == DBNull.Value)
                    {
                        args.Handled = true;
                        return cell.Column.Key;
                    }
                }
            }

            return args.Value;
        }
    }
}

 

Parents
  • 69832
    Offline posted

    I didn't try to reproduce this but I took a look at the implementation and if you are always returning the column's key when the underlying value is null, you can get the same effect by assigning the column's key to the NullText property instead. NullText was desgined for just the purpose you describe here, to affect only the display while leaving the value intact.

Reply Children