2 Replies Latest reply on Feb 19, 2010 5:28 AM by eliza_mfs

    Datagrid checkbox renderer refresh?



      I am using a checkbox renderer for one of the columns in a flex datagrid.
      When i scroll up or down, the checkboxes i have alread clicked, change to different boxes (records). ????
      Not sure if this is a redraw issue. Tried to validate, but did not help.
      Please help.
        • 1. Re: Datagrid checkbox renderer refresh?
          ntsiii Level 3
          First, this forum is for Flex version 1.5, note the title, and it is nearly abandoned. You need to post questions in the "Flex General Discussion" forum instead.

          Item renderer are "recycled". that is, Flex only renderes the number needed to display, then sets the data for each of those when you scroll, or when the data otherwise changes.

          So the "Selected" attribute must be set based on a value in the dataProvider item. In fact, any visual element whose state is row-based must be ste based on the data.

          See this blog for more info:
          http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html

          Tracy Spratt
          • 2. Re: Datagrid checkbox renderer refresh?
            eliza_mfs Level 1

            When we add a customized checkbox column to a datagrid in .net (windows application) , the default property allows to check or uncheck the column using a double click. On the first click it selects the column and on the second click the column is either checked or unchecked.
            To change this default property, we need to handle the click event on grid and modify the selected cell value. Here is the sample code to achieve this.
            [C#.NET VS 2003 , Code to add checkbox column to grid using table style property]
            dgItemDetails.TableStyles.Clear(); // clears the tablestyle (dgItemDetails is the name of grid)
            DataGridTableStyle dgt = new DataGridTableStyle();
            dgt.MappingName = "ItemDetails";
              
            DataGridBoolColumn dgbCol = new DataGridBoolColumn(); // creates the checkbox column
            dgbCol.MappingName = "Select";
            dgbCol.HeaderText = "";
            dgbCol.Width = 40;
            dgbCol.AllowNull = false;
            dgbCol.Alignment = HorizontalAlignment.Left;
            dgt.GridColumnStyles.Add(dgbCol);
            dgItemDetails.TableStyles.Add(dgt); // add