Sunday 1 July 2012

Datagridview: The best thing about Dapfor’s Datagridview

The best thing about using Dapfor’s application is its capability to offers lots of feature and that too with good performance. One of the most important features of Dapfor application is its Datagridview. Datagridview is not only stable but also supports various version of CLR such as 2.0, 3.0, 3.5 and 4.0. This is the main reason that Datagridview is used in many applications of Dapfor. Users can find many others Datagridview from many organizations but they lack the capability to handle event-based model efficiently as Dapfor applications do. Others organizations Datagridview doesn’t face any kind of problem while handling non-event based model but when it comes to event based model there is no better than the Dapfor’s Datagridview. Dapfor’s Datagridview also consumes less system and memory resources which make them among the best in the business. 
For example, take the sorting mechanism on the Datagridview. In such kind of scenario all the relevant information’s are stored in grid headers. Look at the code below which states the sort direction using simple inbuilt methods provided by the Dapfor’s Datagridview.
//Get top-level header
Header header = grid.Headers [0];

header["Product"].SortDirection = SortDirection.Ascending;
header["Price"].SortDirection = SortDirection.Descending;
If the users want to restrict the sorting property from the GUI, they can use the Column.Sortable property. Datagridview implements the IComparable interface for applying sorting on the view. During sorting objects generally returns simple data types such as int, float, string pr Timespan. IComparable interface uses these data types for sorting purposes on the Datagridview. Dapfor’s Datagridview also has the capability to handle sorting for different rows as well for complex type of data types. The task of the IComparable interface is to compare between the simple data types and the complex data types. This interface doesn’t take into account about the stocks which is present on the grid cells. The code below gives you the insight about the Datagridview sorting using the DateTime value.
class AnotherDateSortingExample
{
    private readonly DateTime _date;

    public DateExample(DateTime date)
    {
        _date = date;
    }

    public DateTime Date
    {
        get { return _date; }
    }
}

//Create header and column
grid.Headers.Add(new Header());
grid.Headers[0].Add(new Column("Date"));

//Configure the header
grid.Headers[0].StretchMode = ColumnStretchMode.All;
grid.Headers[0][0].SortDirection = SortDirection.Ascending;
grid.Headers[0]["Date"].Format = new StringFormat("d", new CultureInfo("fr-FR"));

//Populate grid with random data
Random random = new Random();
BindingList<DateExample> source = new BindingList<DateExample>();
for (int i = 0; i < 6; ++i)
{
    source.Add(new DateExample(DateTime.Now + TimeSpan.FromDays(random.Next(1000))));
}
grid.DataSource = source;
Dapfor’s Datagridview provides provision to do user defined sorting technique. This can be achieved using the ICustomSort interface which helps is setting the sorting rules.
//An implementation ICustomSort that sorts values by day of week
class MonthOfYearCustomSort : ICustomSort
{
    public int Compare(Row row1, Row row2, string fieldId, object value1, object value2, int defaultResult)
    {
        if(fieldId == "Date")
        {
            DateTime d1 = (DateTime) value1;
            DateTime d2 = (DateTime) value2;

            if (d1. MonthOfYear != d2. MonthOfYear)
            {
                return d1. MonthOfYear > d2.MonthOfYear? 1 : -1;   
            }
        }
        return defaultResult;
    }
}

//Setup custom sorting
grid.CustomSort = new MonthOfYearCustomSort();

1 comment:

  1. Net Grid is a high-performance grid based on Win Forms technology optimized for large data volume and consuming minimum memory and CPU resources.
    http://www.dapfor.com/en/net-suite/net-grid/features/performance

    ReplyDelete