将新行添加到datagridview时显示消息 [英] show a message when new row added to datagridview
问题描述
嘿
我有一个Windows窗体应用程序(见下文),我有一个datagridview。
我已将datagridview链接到sql数据库。
我为我的应用程序添加了一个计时器,用数据库中的新记录更新datagridview。
现在我只想在向datagridview添加新行时向用户显示一条消息(警告),它不应该阻止win表单应用程序运行。 />
我该怎么办?
谢谢
到目前为止,这是我的Windows表单应用程序:
{
public partial class Form1:Form
{
定时器计时器= 新 Timer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load( object sender,EventArgs e)
{
this .CarUpdateTableAdapter.Fill(此跨度> .mySQLDataSource.CarUpdate);
this .dataGridView1.Sort( this .dataGridView1.Columns [ 18 ],ListSortDirection.Descending);
dataGridView1.AutoResizeColumns();
timer.Interval = 300000 ;
timer.Tick + = new EventHandler(UpdateDataGridView);
timer.Start();
}
private void UpdateDataGridView(< span class =code-keyword> object sender,EventArgs e)
{
this .CarUpdateTableAdapter.Fill(此跨度> .mySQLDataSource.CarUpdate);
}
}
}
private void grd_movement_RowsAdded( object sender,DataGridViewRowsAddedEventArgs e)
{
MessageBox.Show( Your message here); // 最好在标签中显示你的消息.....
}
它是一个事件......只需选择datagridview并转到属性并选择事件选项卡。 ...
你会看到 RowAdded事件 ....双击它添加代码
这是一个在添加新行时会自动调用的事件.....
by使用以下代码,您可以删除事件和ena添加行的活动
..................
所以当datagridview第一次加载确保在加载后删除event.soon
再次启用
............. .....
//事件放弃
<前lang =cs> this .dataGridView1.RowsAdded - = new System.Windows.Forms.DataGridViewRowsAddedEventHandler( this .dataGridView1_RowsAdded);
//事件启用
此 .dataGridView1.RowsAdded + = new System.Windows.Forms.DataGridViewRowsAddedEventHandler( this .dataGridView1_RowsAdded);
Hey
I have a windows form application(See below) in which I have a datagridview.
I have linked the datagridview to a sql database.
I added a timer for my application to update the datagridview with new records from the database.
Now I would like to display a message (alert) to the user only when new rows are added to the datagridview and it should not stop the win form application from running.
How can I do this please?
Thanks
This is my windows form application so far:
{
public partial class Form1 : Form
{
Timer timer = new Timer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.CarUpdateTableAdapter.Fill(this.mySQLDataSource.CarUpdate);
this.dataGridView1.Sort(this.dataGridView1.Columns[18], ListSortDirection.Descending);
dataGridView1.AutoResizeColumns();
timer.Interval = 300000;
timer.Tick += new EventHandler(UpdateDataGridView);
timer.Start();
}
private void UpdateDataGridView(object sender, EventArgs e)
{
this.CarUpdateTableAdapter.Fill(this.mySQLDataSource.CarUpdate);
}
}
}
private void grd_movement_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { MessageBox.Show("Your Message here");// it is better to show u r message in a label ..... }
Its a event ...Just select the datagridview and go to properties and select event tab.....
There u will see RowAdded event ....double click it and add the code
It is an event it will be called automatically when new rows are added.....
by using the following code u can drop the event and enable the event for row added
..................
So when datagridview is loaded for the first time make sure to drop the event.soon after loading
enable the even again
..................
//event Drop
this.dataGridView1.RowsAdded -= new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.dataGridView1_RowsAdded);
//event enable
this.dataGridView1.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.dataGridView1_RowsAdded);
这篇关于将新行添加到datagridview时显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!