Heres a snippet of code for adding the comboBox Columns:
Expand|Select|Wrap|Line Numbers
- DataGridViewComboBoxColumn ddlConfig = new DataGridViewComboBoxColumn();
- ddlConfig.HeaderText = "Config";
- ddlConfig.Items.Add("No Access");
- ddlConfig.Items.Add("Full Access");
- ddlConfig.DisplayIndex = 2;
- dataGridView1.Columns.Add(ddlConfig);
Expand|Select|Wrap|Line Numbers
- string primKey = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
- if (dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText.ToString() == "Config" ||
- dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText.ToString() == "Reports" ||
- dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText.ToString() == "Groups" ||
- dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText.ToString() == "Predefined" ||
- dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText.ToString() == "Permissions")
- {
- int val = 0;
- if (dataGridView1.CurrentCell.Value.ToString() == "No Access")
- val = 0;
- else if (dataGridView1.CurrentCell.Value.ToString() == "Full Access")
- val = 1;
- else
- val = 0;
- string command = "UPDATE Permissions SET " + dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText.ToString() + "='" + val + "' WHERE ID = " + primKey;
- try
- {
- conn.Open();
- SqlCommand cmd = new SqlCommand(command, conn);
- cmd.ExecuteNonQuery();
- }
- catch
- {
- }
- finally
- {
- conn.Close();
- }
If theres not a simpler way to do this can someone please tell me the best way to set the values for each row... Because currently theres a datasource binded to the dgv and i just add the other columns on (hence the DisplayIndex property).
Many Thanks,
Regards,
Piercy