This is a migrated thread and some comments may be shown as answers.

Removing/Hiding a GridItem inside of _ItemCreated

1 Answer 33 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dmitri
Top achievements
Rank 1
Dmitri asked on 16 Dec 2015, 02:10 PM

I have a dynamically loaded grid (automatic column generation, data table as a source) and currently I use the code below to catch the rows as they are created and compare their content to the previous row to track changes in the data. If nothing changed i want to hide the row from the grid. Based on everything i have read the code below should work properly and it does for highlighting column changes BUT for some reason its ignoring the e.Item.Visible setting and still showing rows that I have set to hidden. Thanks in advance!

01.System.Data.DataTable dt = null;
02.int rowCnt = 0;
03.List<int> colsNotToTrack = new List<int>();
04.protected void rgResults_ItemCreated(object sender, GridItemEventArgs e)
05.{
06.    if (compareLines && e.Item is GridDataItem)
07.    {
08.        if (rowCnt > 0)
09.        {
10.            bool changed = false;
11.            for (int i = 2; i < e.Item.Cells.Count; i++)
12.            {
13.                if (colsNotToTrack.Contains(i))
14.                    continue;
15.                if (dt.Rows[rowCnt][i - 2].ToString() != dt.Rows[rowCnt - 1][i - 2].ToString())
16.                {
17.                    e.Item.Cells[i].BackColor = System.Drawing.Color.LightSalmon;
18.                    changed = true;
19.                }
20.            }
21.            e.Item.Visible = changed;
22.        }
23.        rowCnt++;
24.    }
25.     
26.}

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 21 Dec 2015, 08:43 AM
Hi Dmitri,

Please try using Display property instead of Visible. This should hide the rows correctly on ItemCreated event handler.

Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Dmitri
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or