Suganda Suganda

Suganda Suganda

  • NA
  • 24
  • 10.7k

How to customize combobox and textbox in datagridview

Feb 19 2018 6:50 AM
I learn to create form diagnose for expert system. And i design winform like this:
 
Combobox in column 3, and textbox in column 4. 
 
 
 
How to use selectedindex in DataGridViewCheckBoxColumn, get value like (0,2;0,4;0,6;0,8) from combobox and put them to DataGridViewTextBoxColumn one by one in every rows?
 
this my code:
 
private void ShowDBGrid()
{
CONN = new Conn();
SQL = "SELECT * FROM evidence";
try
{
CONN.OpenConn();
MYCMD = new MySqlCommand(SQL);
MYDA = new MySqlDataAdapter(SQL, CONN.MYCONN);
DataSet DS = new DataSet();
MYDA.Fill(DS);
dgvDiagnose.DataSource = DS.Tables[0].DefaultView;
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
//checkBoxColumn.Width = 10;
checkBoxColumn.Name = "checkBoxColumn";
dgvDiagnose.Columns.Insert(0, checkBoxColumn);
dgvDiagnose.Columns[1].HeaderText = "";
DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
comboBoxColumn.HeaderText = "";
//comboBoxColumn.Width = 30;
comboBoxColumn.Name = "comboBoxColumn";
comboBoxColumn.Items.Add("CF User");
comboBoxColumn.Items.Add("Tidak Tahu");
comboBoxColumn.Items.Add("Kemungkinan Besar");
comboBoxColumn.Items.Add("Hampir Pasti");
comboBoxColumn.Items.Add("Pasti");
dgvDiagnose.Columns.Insert(3, comboBoxColumn);
DataGridViewTextBoxColumn textBoxColumn = new DataGridViewTextBoxColumn();
textBoxColumn.HeaderText = "";
textBoxColumn.Width = 30;
textBoxColumn.Name = "textBoxColumn";
dgvDiagnose.Columns.Insert(4, textBoxColumn);
}
catch (Exception)
{
MessageBox.Show("Program error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
}

Answers (2)