I have a form using dataGridView
and CellFormatting
. One of the columns in my dataGridView
is a "Timer" which should basically show how long that row has been in my dataGridView
.
What I have so far (referencing How do I display a digital timer (StopWatch) in datagridview column dynamically c#?)
public Form1()
{
InitializeComponent();
FillData();
dataGridView.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.cell_formatting);
this.Controls.Add(dataGridView);
start_timer();
}
void start_timer()
{
System.Windows.Forms.Timer clock = new System.Windows.Forms.Timer();
clock.Interval = 1000;
clock.Tick += new EventHandler(clock_tick);
clock.Enabled = true;
}
void clock_tick(object sender, EventArgs e)
{
foreach(DataGridViewRow row in dataGridView.Rows)
{
//????
}
}
The difference between the aforementioned thread and my situation is I'm using DataGridView
whereas... I'm not sure what the other user was using. I don't seem to have access to "DataRow" like he does. When I try to use DataRow
in my foreach loop, I get:
Unable to cast object of type 'System.Windows.Forms.DataGridViewRow' to type 'System.Data.DataRow'.
I could try checking each row for a certain value that I manually insert as a flag, then set that row[column] = DateTime.Now
(with some math to determine length that it's been in there..)
Any advice would be appreciated!
@Reza Aghaei fixed it. Simply updating each object in my datasource then datasource.ResetBindings()
each tick.
Thanks!