Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

change header cell based on current cell

$
0
0

I have the below code working, but there has GOT to be a better way...

Whenever a cell change event happens, check it if is one of our target cells, if so change the first character of the headertext:

privatevoidradGridView1_CurrentCellChanged(objectsender, CurrentCellChangedEventArgs e)
        {
            var test = e.NewCell;
 
            if(test.ColumnInfo.Name == "podName")
            {
                this.radGridView1.Columns["podName"].HeaderText = "*Name";
                this.radGridView1.Columns["podTime"].HeaderText = "Time";
                this.radGridView1.Columns["podDate"].HeaderText = "Date";
                this.radGridView1.Columns["podQty"].HeaderText = "Qty";
            }
            else
            {
                this.radGridView1.Columns["podName"].HeaderText = "Name";
            }
            if(test.ColumnInfo.Name == "podTime")
            {
                this.radGridView1.Columns["podName"].HeaderText = "Name";
                this.radGridView1.Columns["podTime"].HeaderText = "*Time";
                this.radGridView1.Columns["podDate"].HeaderText = "Date";
                this.radGridView1.Columns["podQty"].HeaderText = "Qty";
            }
            else
            {
                this.radGridView1.Columns["podTime"].HeaderText = "Time";
            }
            if(test.ColumnInfo.Name == "podDate")
            {
                this.radGridView1.Columns["podName"].HeaderText = "Name";
                this.radGridView1.Columns["podTime"].HeaderText = "Time";
                this.radGridView1.Columns["podDate"].HeaderText = "*Date";
                this.radGridView1.Columns["podQty"].HeaderText = "Qty";
            }
            else
            {
                this.radGridView1.Columns["podDate"].HeaderText = "Date";
            }
            if(test.ColumnInfo.Name == "podQty")
            {
                this.radGridView1.Columns["podName"].HeaderText = "Name";
                this.radGridView1.Columns["podTime"].HeaderText = "Time";
                this.radGridView1.Columns["podDate"].HeaderText = "Date";
                this.radGridView1.Columns["podQty"].HeaderText = "*Qty";
            }
            else
            {
                this.radGridView1.Columns["podQty"].HeaderText = "Qty";
            }
        }

 

then in the cell formatting event look if the first character of the cell is a "*"

privatevoidradGridView1_ViewCellFormatting(objectsender, CellFormattingEventArgs e)
       {
           if(e.CellElement isGridHeaderCellElement)
           {
               try
               {
                   //var test = e.Column.HeaderText.ToString();
                   var test = e.Column.HeaderText.ToString().Substring(0, 1);
                
                   if(test == "*")
                   {
                       e.CellElement.DrawBorder = true;
                       e.CellElement.DrawFill = true;
                       e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                       e.CellElement.BackColor = Color.White;
                       //  e.CellElement.ForeColor = Color.Red;
                   }
                   else
                   {
                       e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);
                       e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                       e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
                       e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                       e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
                   }
               }
               catch(Exception)
               {
                   //throw;
               }
           }


Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>