如何更新winforms中的数据网格视图? [英] how to update data grid view in winforms?
问题描述
using System;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间项目
{
public partial class frmViewBookings:Form
{
public frmViewBookings()
{
InitializeComponent() ;
}
private void btnClose_Click(object sender,EventArgs e)
{
Form3 mainpage = new Form3();
mainpage.Show();
this.Close();
}
private void frmViewBookings_Load(object sender,EventArgs e)
{
// TODO:这行代码将数据加载到usersDataSet1.Booking表中。您可以根据需要移动或移除它。
this.bookingTableAdapter.Fill(this.usersDataSet1.Booking);
}
}
}
您可以使用将datagridview绑定到源的datagridview的DataSource属性。例如。数据表。
无论何时编辑datatable,datagridview都会更新。
您还可以通过添加行和列手动修改datagridview,但这更有用。
编辑:如果希望更改更新到datagridview,您需要修改作为绑定源的datatable。
I have a page in my winforms, where i want to display all the data on a table so the user can see the information in the table but on the winforms. i have not done this before so need some guidance from you people, i want it to consistently (when new records are added) update and be editable so a row can be deleted if it needs to. the table i have is "booking" and the form on which i can add data to this table is "frmBooking" so i want booking data made whilst the program is run to be stored in the datagridview so the user can view their bookings made. thanks the code i have is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace project
{
public partial class frmViewBookings : Form
{
public frmViewBookings()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
Form3 mainpage = new Form3();
mainpage.Show();
this.Close();
}
private void frmViewBookings_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'usersDataSet1.Booking' table. You can move, or remove it, as needed.
this.bookingTableAdapter.Fill(this.usersDataSet1.Booking);
}
}
}
You can use the DataSource property of the datagridview which binds the datagridview to a source. eg. A DataTable.
Whenever the datatable is edited the datagridview is updated.
You could also modifiy the datagridview manually by adding rows and columns but this is a bit more work.
Edit: If you wish your changes to update to the datagridview you need to modify the datatable which is the binding source.
这篇关于如何更新winforms中的数据网格视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!