我想处理Checked
的事件CheckBox
我的专栏DataGridView
并根据列检查值(真/假)执行操作。我尝试使用CellDirtyStateChanged
没有任何成功。事实上,我想在用户选中或取消选中复选框后立即检测选中的更改。
这是关于我的应用程序的描述。我是 C# 新手,正在为一个为旅行者提供客房的地方制作一个“预订我的房间”应用程序。这个屏幕可以很好地解释我希望实现的目标;
This is a .GIF of a software which calculates hourly pay of an employee and this photo is an illustration of what actually I want to build:
用于显示我的表格的代码DataGridView
is:
OleDbConnection connection = new OleDbConnection();
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select id,cusid,cusname,timein,
timeout,duration,amount,remark from entry";
command.CommandText = query;
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
我使用这个添加了复选框列;
DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "logout";
checkColumn.HeaderText = "Logout";
checkColumn.Width = 50;
checkColumn.ReadOnly = false;
checkColumn.FillWeight = 10;
dataGridView1.Columns.Add(checkColumn);
每当用户从登录屏幕登录时,都会在表中插入一个新行,因此 dgv 将更新,并包含相应的用户条目。
我不明白如何将这些复选框与 datagridview 链接起来,我尝试了 celldirtystatechanged 但没有任何效果,将行与复选框关联起来的正确方法是什么。