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

[Solved] Changing column headers broken in new Release

1 Answer 98 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
FieldTRAKS
Top achievements
Rank 1
FieldTRAKS asked on 14 Aug 2009, 01:22 AM
I previously had bound my XML stream to a gridview. I was using a modified version of Vlad's(from telerik) DataTable class. I was having a problem with the column names (my xml nodes contained escaped special characters) so I created a workaround that named each column in the data class to be a sequential value (H1, H2, H3). Once the grid was bound I iterated through the grid columns and renamed them to their true names. This worked splendidly in the july release. After I updated to the current release this does not work. What is strange is that if I drag the frozen column bar the column names in the grid update themselves and appear as expected. I tried to force the grid to update itself but that did not work. I even tried to force it to rebind once after renaming the columns and that caused IE to dissapear.

This is the code I was using that was working....

        void gridview_DataLoaded(object sender, EventArgs e)
        {  
            int cnt = 0;
            foreach (Telerik.Windows.Controls.GridViewColumn gc in gridview.Columns)
            {
                gc.Header = table.Columns[cnt].Alias;
                cnt++;
            }
        }



Here is the code for  the entire class....


    public partial class FTGenericReport : UserControl
    {

        FTGenericReportWindow pWindow;

        public FTGenericReportWindow PWindow
        {
            get { return pWindow; }
            set { pWindow = value; }
        }

        List<XElement>  report ;
        Telerik.Data.DataTable table = new Telerik.Data.DataTable();
            List<XElement> schemanodes;

            string schemams, schemans;

        public FTGenericReport( )
        {
            InitializeComponent();



        }

   
        

        public  void Init(List<XElement> report, List<XElement> sn)
        {
            this.report = report;

            schemanodes = sn;

            CreateColumns();
            
            CreateRows();
            gridview.DataLoaded += new EventHandler<EventArgs>(gridview_DataLoaded);
    

            try
            {
                gridview.ItemsSource = table;

            }

            catch(Exception ex)
            {

            }
        
        }

     

        void gridview_DataLoaded(object sender, EventArgs e)
        {  
            int cnt = 0;
            foreach (Telerik.Windows.Controls.GridViewColumn gc in gridview.Columns)
            {
                gc.Header = table.Columns[cnt].Alias;
                cnt++;
            }
        }

        private void CreateRows()
        {

           foreach (XElement datanode in report)
            {

                Telerik.Data.DataRow dr = new Telerik.Data.DataRow();
                foreach (XElement xe in schemanodes)
                {



                    string name = xe.Attribute(XName.Get("name")).Value;
                    IEnumerable<Telerik.Data.DataColumn> cls = table.Columns.Where(c => c.DbName == name);
                    if (cls.Count() == 1)
                    {

                        try
                        {

                            XElement rn = datanode.Elements().Single(c => c.Name.LocalName == name);
                            dr[cls.ElementAt(0).ColumnName] = rn.Value;
                        }
                        catch
                        {
                            dr[cls.ElementAt(0).ColumnName] = "";
                        }


                    }
                }
                table.Rows.Add(dr);
            }
         
            table.Rows.TrimExcess();

            
        }
        
        private void CreateColumns()
        {
          int cnt = 0;


             foreach (XElement xe in schemanodes)
            {
                 string dbname = xe.Attribute(XName.Get("name")).Value;
                string name = FTSilverControls.Utility.XMLNameResolver(dbname, false);

                Telerik.Data.DataColumn dc = new Telerik.Data.DataColumn() { ColumnName = "F" + cnt.ToString(), DataType = typeof(string),Alias =name , DbName = dbname};
                table.Columns.Add(dc);
                cnt++;
            }
       

        }

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Aug 2009, 09:07 AM
Hello Dave,

The bug was identified and fixed immediately. The fix will be part of our internal build (this Friday) however you can contact the support to receive custom build.

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
FieldTRAKS
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or