All,
I have a DataGridView bound to an XML file, then I add an unbound column of checkboxes to the DGV.
private void btnReconcile_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(txtPath.Text);
DataSet modds = new DataSet();
DataTable dt = new DataTable();
dt = ds.Tables[0].Clone();
foreach (DataTable tbl in ds.Tables)
{
progRecords.Value = 0;
progRecords.Minimum = 0;
progRecords.Maximum = tbl.Rows.Count;
foreach (DataRow dr in tbl.Rows)
{
progRecords.Value++;
try
{
myCommand.Connection = myConnection;
myCommand.CommandText = "SELECT COUNT(*) FROM Contacts WHERE email1 LIKE '%" + dr["Email"].ToString() + "%'";
nCount = (int)myCommand.ExecuteScalar();
if (nCount <= 0)
{
WriteContactToXML(dr);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
modds.ReadXml("\\WriteContacts.xml");
dataGridView1.DataSource = modds.Tables[0];
dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
CreateUnboundButtonColumn();
MessageBox.Show("Verification Complete!");
}
And the code to create the column is as follows.
private void CreateUnboundButtonColumn()
{
if (columnAdded == true) return;
// Initialize the button column.
DataGridViewCheckBoxColumn checkBoxColumn =
new DataGridViewCheckBoxColumn();
checkBoxColumn.Name = "Add";
checkBoxColumn.HeaderText = "Add";
checkBoxColumn.TrueValue = false;
checkBoxColumn.FalseValue = true;
dataGridView1.AutoGenerateColumns = false;
// Use the Text property for the button text for all cells rather
// than using each cell's value as the text for its own button.
// Add the button column to the control.
dataGridView1.Columns.Insert(0, checkBoxColumn);
columnAdded = true;
}
In my data source, I have a node that is set to either "true" or "false". How can I get the checkbox to be bound to that node?
Also, side note, I'm not sure that my DataGridViewCellEventHandler is correct. So, would I have the data source be modified in the event handler?
Thanks,
Andrew