jeudi 28 août 2014

How to change back a DataGridViewComboBoxCell to DataGridviewCell


Vote count:

0




I have a datagridview.


when i doubled click on a cell it changes to DataGridViewComboBoxCell , then i want when user selected an index , it changes back to DataGridviewCell like before with a new value.


what should i do?



namespace GridEnterChanged
{
public partial class Form1 : Form
{
DataTable dt;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
sqlConnection1.Open();
dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter("select * from customer", sqlConnection1);
sda.Fill(dt);
dataGridView1.EditingControlShowing +=dataGridView1_EditingControlShowing;
dataGridView1.CellEndEdit+=dataGridView1_CellEndEdit;
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "FName";
comboBox1.ValueMember = "CustomerID";

DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb.DataSource = dt;
cmb.DisplayMember = "FName";
cmb.ValueMember = "CustomerID";

cmb.HeaderText = "Select Data";
cmb.Name = "cmb";
cmb.MaxDropDownItems = 4;
//cmb.Items.Add("True");
//cmb.Items.Add("False");
dataGridView1.Columns.Add(cmb);
dataGridView1.DataSource = dt;


sqlConnection1.Close();

dataGridView1.DataError += dataGridView1_DataError;
}

private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
//throw new NotImplementedException();
}
private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{ DataGridView dg = sender as DataGridView;
MessageBox.Show(dg.SelectedCells[0].ToString()+e.ColumnIndex+" "+e.RowIndex);

DataGridViewComboBoxCell dvc = new DataGridViewComboBoxCell();

dvc.DataSource = dt;
//int selectedrowindex = e.SelectedCells[0].RowIndex;
int tmp = dg.CurrentCell.ColumnIndex;
dvc.DisplayMember = dg.Columns[tmp].HeaderText;
dvc.ValueMember = "CustomerID";
this.dataGridView1[e.ColumnIndex, e.RowIndex] = dvc;

}


asked 53 secs ago







How to change back a DataGridViewComboBoxCell to DataGridviewCell

Aucun commentaire:

Enregistrer un commentaire