I want to handle Checked
event of CheckBox
columns in my DataGridView
and perform an operation based on column checked value (true/false). I tried to use CellDirtyStateChanged
without any success. In fact I want to detect checked change immediately after the user checks or unchecks the check box.
Here is a description about my application. I am new to c# and making a "book my room" app for a place which provides guest housing to travelers. This screen may explain well what I wish to achieve;
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:
Code for displaying my table in 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;
I added the checkbox column using this;
DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "logout";
checkColumn.HeaderText = "Logout";
checkColumn.Width = 50;
checkColumn.ReadOnly = false;
checkColumn.FillWeight = 10;
dataGridView1.Columns.Add(checkColumn);
Whenever a user logs in from the login screen a new row will be inserted in the table and hence the dgv will be updated, with corresponding users entry.
I don't understand how to link those checkboxes with datagridview I tried celldirtystatechanged but nothing works, what would be the right way to associate the row with checkbox.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…