'Windows Forms - Change Datagrid Cell Value when Button in another Form is clicked
Solution 1:[1]
Setup an event in Timer form and pass the value, here is a basic example. Adjust to work with your code in regards to your DataGridView and if the value being passed is not a string, change it.
public partial class TimerForm : Form
{
public delegate void OnWhatEver(string sender);
public event OnWhatEver WhatEverHandler;
public TimerForm()
{
InitializeComponent();
}
private void WhatEverButton_Click(object sender, EventArgs e)
{
WhatEverHandler?.Invoke($"{sender:f}");
}
}
Main Form, one button, one label
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void OpenTimerForm_Click(object sender, EventArgs e)
{
TimerForm form = new TimerForm();
form.WhatEverHandler += OnWhatEverEvent;
form.ShowDialog();
}
private void OnWhatEverEvent(string sender)
{
label1.Text = sender;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Karen Payne |


