Click here to Skip to main content
15,887,337 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
How do I get the max value of every columns of a dynamically created RadGridView?
And turn them red when found?

Thanks
Posted
Comments
joshrduncan2012 11-Jun-14 11:40am    
What have you tried? Where are you stuck? Can you show us your code, please?
pierrewhy 11-Jun-14 12:00pm    
I've been at it for two days.

I get lots of examples from other forums but nothing works.
The simple way would be to look thru every rows of every column and get the max value within that column.
I need to have the max value turn red in every column.

I've tried foreach loop and for iteration.

Since the grids are created dynamic I never know the number of columns or the header's name.

Every coding I had so far has been deleted out of frustation.

Hopefully you can help,

thanks.
pierrewhy 11-Jun-14 12:17pm    
I don't even have acces to this simple command.

foreach (DataGridRow row in firstcontrol.RadGridView1.Rows)

It doesn't accept the symbol .Rows
ZurdoDev 11-Jun-14 12:15pm    
Not sure if this would be easier but if you can include a column in your sql that flags the max. For each column have another one that is columnname_max and set to 1 or 0.
pierrewhy 11-Jun-14 12:21pm    
I'm not using SQL to get the data. It comes from another application that produce a list of table that need to be converted for and I have to an ObservableCollection<ilist> before becoming the itemsource of the grid.

1 solution

Please try this out handling the PreRender event of the RadGrid to format the cell which is largest among all rows of the columns added in array and let me know if this helps for you :-

C#
protected void MyRadGrid_PreRender(object sender, EventArgs e)
{
    string[] columns = { "TaxID", "Tax1", "Tax2", "Tax3" };
    foreach (string colName in columns)
    {
        int i = -1;
        decimal max = decimal.MinValue;
        foreach (GridDataItem dtItem in MyRadGrid.MasterTableView.Items)
        {
            decimal currentNo = decimal.Parse(dataItem[colName].Text);
            if (currentNo > maxNumber)
            {
                max = currentNo;
                i = dtItem.ItemIndex;
            }
        }

        if (i >= 0)
        {
            GridTableCell gtCell = (MyRadGrid.Items[i] as GridDataItem)[colName] as GridTableCell;
            gtCell.BackColor = System.Drawing.Color.Red;
        }
    }
}


Hope this will definitely be of help.
 
Share this answer
 
v2
Comments
pierrewhy 12-Jun-14 16:04pm    
Unfortunaly I do not know how many columns I have, the columns name or the type of data. I have to eliminate the strings and find the max value of the remaining data, be it int, double etc etc.
And that max value, one for every columns, has to be highilited on the datagrid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900