# grid-real-time-updates

> Grid that appends rows from a background timer to demonstrate live updates without losing selection and scroll position.

**Framework:** winforms  **Component:** Grid  **Variant:** real-time-updates

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/winforms/grid-real-time-updates.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.SfDataGrid.WinForms
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/grid-real-time-updates/grid.Designer.cs

```cs
using Syncfusion.Windows.Forms;
using Syncfusion.WinForms.DataGrid;
using System.Drawing;
using System.Windows.Forms;

namespace RealTimeUpdates
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
                //Disposing events
                sfDataGrid.DrawCell -= SfDataGrid_DrawCell;
                startTimerBtn.Click -= ButtonClick_Click;
                frequencySlider.Scroll -= FrequencySlider_Scroll;
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.optionLabel = new System.Windows.Forms.Label();
            this.sfDataGrid = new Syncfusion.WinForms.DataGrid.SfDataGrid();
            this.frequencyLbl = new System.Windows.Forms.Label();
            this.timerStatusLbl = new System.Windows.Forms.Label();
            this.frequencyRangeLbl = new System.Windows.Forms.Label();
            this.maxfrequency = new System.Windows.Forms.Label();
            this.numOfUpdate = new System.Windows.Forms.Label();
            this.frequencySlider = new System.Windows.Forms.TrackBar();
            this.startTimerBtn = new System.Windows.Forms.Button();
            this.frequencyChanging = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.sfDataGrid)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.frequencySlider)).BeginInit();
            this.SuspendLayout();
            //
            // optionLabel
            //
            this.optionLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.optionLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
            this.optionLabel.Location = new System.Drawing.Point(814, 22);
            this.optionLabel.Name = "optionLabel";
            this.optionLabel.Size = new System.Drawing.Size(100, 33);
            this.optionLabel.TabIndex = 4;
            this.optionLabel.Text = "Options:";
            //
            // sfDataGrid
            //
            this.sfDataGrid.AccessibleName = "Table";
            this.sfDataGrid.AllowEditing = false;
            this.sfDataGrid.AllowGrouping = false;
            this.sfDataGrid.AllowSorting = false;
            this.sfDataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.sfDataGrid.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.Fill;
            this.sfDataGrid.BackColor = System.Drawing.SystemColors.Window;
            this.sfDataGrid.Location = new System.Drawing.Point(10, 5);
            this.sfDataGrid.Name = "sfDataGrid";
            this.sfDataGrid.RowHeight = (int)DpiAware.LogicalToDeviceUnits(21.0f);
            this.sfDataGrid.Size = new System.Drawing.Size(787, 578);
            this.sfDataGrid.TabIndex = 0;
            //
            // frequencyLbl
            //
            this.frequencyLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.frequencyLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
            this.frequencyLbl.Location = new System.Drawing.Point(842, 55);
            this.frequencyLbl.Name = "frequencyLbl";
            this.frequencyLbl.Size = new System.Drawing.Size(141, 29);
            this.frequencyLbl.TabIndex = 5;
            this.frequencyLbl.Text = "Timer Frequency:";
            //
            // timerStatusLbl
            //
            this.timerStatusLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.timerStatusLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
            this.timerStatusLbl.Location = new System.Drawing.Point(842, 162);
            this.timerStatusLbl.Name = "timerStatusLbl";
            this.timerStatusLbl.Size = new System.Drawing.Size(100, 23);
            this.timerStatusLbl.TabIndex = 3;
            this.timerStatusLbl.Text = "Start /Stop Timer";
            //
            // frequencyRangeLbl
            //
            this.frequencyRangeLbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
            this.frequencyRangeLbl.Location = new System.Drawing.Point(21, 9);
            this.frequencyRangeLbl.Name = "frequencyRangeLbl";
            this.frequencyRangeLbl.Size = new System.Drawing.Size(125, 20);
            this.frequencyRangeLbl.TabIndex = 6;
            this.frequencyRangeLbl.Text = "Timer Frequency :";
            //
            // maxfrequency
            //
            this.maxfrequency.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
            this.maxfrequency.Location = new System.Drawing.Point(415, 9);
            this.maxfrequency.Name = "maxfrequency";
            this.maxfrequency.Size = new System.Drawing.Size(200, 20);
            this.maxfrequency.TabIndex = 7;
            this.maxfrequency.Text = "1000";
            //
            // numOfUpdate
            //
            this.numOfUpdate.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
            this.numOfUpdate.Location = new System.Drawing.Point(299, 9);
            this.numOfUpdate.Name = "numOfUpdate";
            this.numOfUpdate.Size = new System.Drawing.Size(110, 20);
            this.numOfUpdate.TabIndex = 8;
            this.numOfUpdate.Text = "No Of Updates :";
            //
            // frequencySlider
            //
            this.frequencySlider.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.frequencySlider.LargeChange = 100;
            this.frequencySlider.Location = new System.Drawing.Point(845, 97);
            this.frequencySlider.Maximum = 1000;
            this.frequencySlider.Minimum = 100;
            this.frequencySlider.Name = "frequencySlider";
            this.frequencySlider.Size = new System.Drawing.Size(104, 45);
            this.frequencySlider.TabIndex = 2;
            this.frequencySlider.TickFrequency = 200;
            this.frequencySlider.Value = 100;
            this.frequencySlider.Scroll += new System.EventHandler(this.FrequencySlider_Scroll);
            //
            // startTimerBtn
            //
            this.startTimerBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.startTimerBtn.Location = new System.Drawing.Point(845, 206);
            this.startTimerBtn.Name = "startTimerBtn";
            this.startTimerBtn.Size = new System.Drawing.Size(100, 33);
            this.startTimerBtn.TabIndex = 1;
            this.startTimerBtn.Text = "Stop Timer";
            this.startTimerBtn.Click += new System.EventHandler(this.ButtonClick_Click);
            //
            // frequencyChanging
            //
            this.frequencyChanging.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
            this.frequencyChanging.Location = new System.Drawing.Point(152, 9);
            this.frequencyChanging.Name = "frequencyChanging";
            this.frequencyChanging.Size = new System.Drawing.Size(150, 20);
            this.frequencyChanging.TabIndex = 9;
            this.frequencyChanging.Text = "100 ms";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Window;
            this.ClientSize = new System.Drawing.Size(1006, 593);
            this.Controls.Add(this.sfDataGrid);
            this.Controls.Add(this.startTimerBtn);
            this.Controls.Add(this.frequencySlider);
            this.Controls.Add(this.timerStatusLbl);
            this.Controls.Add(this.optionLabel);
            this.Controls.Add(this.frequencyLbl);
            this.Controls.Add(this.frequencyRangeLbl);
            this.Controls.Add(this.maxfrequency);
            this.Controls.Add(this.numOfUpdate);
            this.Controls.Add(this.frequencyChanging);
            this.Margin = new System.Windows.Forms.Padding(5);
            this.MinimumSize = new System.Drawing.Size(500, 400);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Real-Time Update";
            ((System.ComponentModel.ISupportInitialize)(this.sfDataGrid)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.frequencySlider)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion

        #region Private members

        private SfDataGrid sfDataGrid;
        private Label optionLabel;
        private Label frequencyLbl;
        private Label frequencyRangeLbl;
        private Button startTimerBtn;
        private TrackBar frequencySlider;
        private Label timerStatusLbl;
        private Label maxfrequency;
        private Label numOfUpdate;
        private Label frequencyChanging;
        private StocksDataCollection collection;
        #endregion
    }
}
```

### src/components/grid-real-time-updates/grid.cs

```cs
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Syncfusion.WinForms.DataGrid.Styles;
using Syncfusion.WinForms.DataGrid.Helpers;
using Syncfusion.WinForms.DataGrid;
using Syncfusion.WinForms.DataGrid.Enums;
using Syncfusion.WinForms.DataGrid.Events;
using Syncfusion.WinForms.Core;
using Syncfusion.WinForms.Core.Enums;

namespace RealTimeUpdates
{
    public partial class Form1 : Form
    {
        #region Constructor
        public Form1()
        {
            InitializeComponent();
            collection = new StocksDataCollection();
            sfDataGrid.DataSource = collection.Stocks;
            sfDataGrid.DrawCell += SfDataGrid_DrawCell;
        }

        #endregion

        #region Event_Method

        /// <summary>
        /// Sets track bar changed to timer.
        /// </summary>
        private void FrequencySlider_Scroll(object sender, EventArgs e)
        {
            double ms = frequencySlider.Value * 2321;
            if (frequencySlider.Value == 100 || frequencySlider.Value == 1000)
                frequencyChanging.Text = "" + frequencySlider.Value + " ms";
            else
                frequencyChanging.Text = "" + frequencySlider.Value + "." + ms + " ms";

            collection.StartTimer(frequencySlider.Value);
            startTimerBtn.Text = "Stop Timer";
        }

        /// <summary>
        /// Used to Start and Stop the timer in button click.
        /// </summary>
        private void ButtonClick_Click(object sender, EventArgs e)
        {
            if (startTimerBtn.Text == "Start Timer")
            {
                collection.StartTimer(frequencySlider.Value);
                startTimerBtn.Text = "Stop Timer";
            }
            else
            {
                collection.StopTimer();
                startTimerBtn.Text = "Start Timer";
            }
        }

        /// <summary>
        /// Used to customize the cell.
        /// </summary>
        private void SfDataGrid_DrawCell(object sender, DrawCellEventArgs e)
        {
            if (this.sfDataGrid.CurrentCell != null && this.sfDataGrid.CurrentCell.IsEditing)
                return;

            if (e.Column.MappingName == "Change" && e.DataRow.RowType == RowType.DefaultRow)
            {
                var graphics = e.Graphics;
                var rect = e.Bounds;
                Rectangle rect1 = new Rectangle(rect.X + 20, rect.Y + 6, rect.Width / 6, rect.Height / 2);
                StringFormat format = new StringFormat();

                e.Style.HorizontalAlignment = HorizontalAlignment.Center;
                var drawingObj = new DrawingHelper();
                var value = drawingObj.GetType().GetMethod("ConvertToStringAlignment", BindingFlags.NonPublic | BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(HorizontalAlignment) }, null).Invoke(drawingObj, new object[] { e.Style.HorizontalAlignment });
                format.Alignment = (StringAlignment)value;

                var value1 = drawingObj.GetType().GetMethod("ConvertToStringAlignment", BindingFlags.NonPublic | BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(System.Windows.Forms.VisualStyles.VerticalAlignment) }, null).Invoke(drawingObj, new object[] { e.Style.VerticalAlignment });
                format.LineAlignment = (StringAlignment)value1;

                if ((e.DataRow.RowData as StockData).Change > 0)
                {
                    ShapesPainter.DrawTriangle(graphics, rect1, TriangleDirection.Up, Brushes.Green, new Pen(Color.Green), true);
                    graphics.DrawString(e.DisplayText, e.Style.Font.GetFont(), new SolidBrush(Color.Green), rect.X + 92, rect.Y + 13, format);
                }
                else
                {
                    ShapesPainter.DrawTriangle(graphics, rect1, TriangleDirection.Down, Brushes.Red, new Pen(Color.Red), true);
                    graphics.DrawString(e.DisplayText, e.Style.Font.GetFont(), new SolidBrush(Color.Red), rect.X + 90, rect.Y + 13, format);
                }
                Pen borderPen = new Pen(Brushes.LightGray);
                graphics.DrawLine(borderPen, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom);
                graphics.DrawLine(borderPen, rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1);
                e.Handled = true;
            }
        }
        #endregion
    }
}
```
