Click here to Skip to main content
15,890,690 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Questionhow to create a boolean property in user control and that can be used ? Pin
ankita.rose911-Aug-12 0:28
ankita.rose911-Aug-12 0:28 
AnswerRe: how to create a boolean property in user control and that can be used ? Pin
Eddy Vluggen11-Aug-12 0:38
professionalEddy Vluggen11-Aug-12 0:38 
QuestionCrossing the UI sync context with a datasource Pin
JoeRip8-Aug-12 12:11
JoeRip8-Aug-12 12:11 
AnswerRe: Crossing the UI sync context with a datasource Pin
Ed Hill _5_8-Aug-12 22:37
Ed Hill _5_8-Aug-12 22:37 
AnswerRe: Crossing the UI sync context with a datasource Pin
Eddy Vluggen8-Aug-12 23:55
professionalEddy Vluggen8-Aug-12 23:55 
GeneralRe: Crossing the UI sync context with a datasource Pin
JoeRip9-Aug-12 11:22
JoeRip9-Aug-12 11:22 
GeneralRe: Crossing the UI sync context with a datasource Pin
Eddy Vluggen9-Aug-12 21:08
professionalEddy Vluggen9-Aug-12 21:08 
AnswerRe: Crossing the UI sync context with a datasource Pin
JoeRip9-Aug-12 10:29
JoeRip9-Aug-12 10:29 
Okay, here is a very simplified version of the problem. Note that the GrowingTable() class is normally in a separate assembly and namespace.

So - I can't just convert the Timer to a FormTimer, unless I pass the form itself to the GrowingTable class, which would be incredibly ugly.

And there's no clear place where I can Invoke, as there is no actual update function (that is hidden in the DataSource mechanism).

C#
using System;
using System.Windows.Forms;

namespace dgv
{
    public partial class Form1 : Form
    {
        DataGridView dgvMain = new DataGridView();
        GrowingTable ra = new GrowingTable();
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            Controls.Add(dgvMain);
            dgvMain.Dock = System.Windows.Forms.DockStyle.Fill;
            dgvMain.Location = new System.Drawing.Point(0, 45);
            dgvMain.DataSource = ra.itemTable;
            ra.Start();
        }

        // this class would normally appear in a separate assembly and namespace
        public class GrowingTable
        {
            public System.Data.DataTable itemTable; 
            private System.Threading.Timer myTimer = null;

            // constructor
            public GrowingTable()
            {
                itemTable = new System.Data.DataTable();
                myTimer = new System.Threading.Timer(this.AddRow, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); 
                for (int i = 0; i < 11; i++)
                {
                    itemTable.Columns.Add(new System.Data.DataColumn(i.ToString(), typeof(System.DateTime)));
                }
            }

            public void Start()
            {
                myTimer.Change(0, 500);
            }

            private void AddRow(object state)
            {
                if (itemTable.Rows.Count < 50)
                {
                    System.Data.DataRow dr = this.itemTable.NewRow();
                    for (int i = 0; i < 11; i++) { dr[i.ToString()] = DateTime.Now; }
                    this.itemTable.Rows.Add(dr);
                }
                else
                {
                    myTimer.Dispose();
                    myTimer = null;
                }
            }
        }
    }
}

GeneralRe: Crossing the UI sync context with a datasource Pin
Ed Hill _5_9-Aug-12 22:45
Ed Hill _5_9-Aug-12 22:45 
GeneralRe: Crossing the UI sync context with a datasource Pin
Eddy Vluggen9-Aug-12 23:01
professionalEddy Vluggen9-Aug-12 23:01 
GeneralRe: Crossing the UI sync context with a datasource Pin
JoeRip9-Aug-12 23:46
JoeRip9-Aug-12 23:46 
GeneralRe: Crossing the UI sync context with a datasource Pin
JoeRip10-Aug-12 16:16
JoeRip10-Aug-12 16:16 
GeneralRe: Crossing the UI sync context with a datasource Pin
Ed Hill _5_11-Aug-12 6:14
Ed Hill _5_11-Aug-12 6:14 
GeneralRe: Crossing the UI sync context with a datasource Pin
JoeRip10-Aug-12 18:47
JoeRip10-Aug-12 18:47 
QuestionIf proccess is running then start coding ! Help Needed Pin
jitforce25858-Aug-12 8:09
jitforce25858-Aug-12 8:09 
AnswerRe: If proccess is running then start coding ! Help Needed Pin
jitforce25858-Aug-12 8:58
jitforce25858-Aug-12 8:58 
QuestionA Way Capturing Straight the Active Windows Only ?? Pin
jitforce25858-Aug-12 4:30
jitforce25858-Aug-12 4:30 
AnswerRe: A Way Capturing Straight the Active Windows Only ?? Pin
Pete O'Hanlon8-Aug-12 4:48
mvePete O'Hanlon8-Aug-12 4:48 
GeneralRe: A Way Capturing Straight the Active Windows Only ?? Pin
jitforce25858-Aug-12 5:05
jitforce25858-Aug-12 5:05 
GeneralRe: A Way Capturing Straight the Active Windows Only ?? Pin
Pete O'Hanlon8-Aug-12 5:10
mvePete O'Hanlon8-Aug-12 5:10 
GeneralRe: A Way Capturing Straight the Active Windows Only ?? Pin
jitforce25858-Aug-12 5:34
jitforce25858-Aug-12 5:34 
GeneralRe: A Way Capturing Straight the Active Windows Only ?? Pin
jitforce25858-Aug-12 6:10
jitforce25858-Aug-12 6:10 
GeneralRe: A Way Capturing Straight the Active Windows Only ?? Pin
Pete O'Hanlon8-Aug-12 7:28
mvePete O'Hanlon8-Aug-12 7:28 
GeneralRe: A Way Capturing Straight the Active Windows Only ?? Pin
jitforce25858-Aug-12 8:07
jitforce25858-Aug-12 8:07 
Question.net framework 4 takes much time than 2.0. Why? Pin
ruby_e_s8-Aug-12 2:26
ruby_e_s8-Aug-12 2:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.