mahesh waghela

mahesh waghela

  • NA
  • 93
  • 113.8k

Columns Order In Datagridview

Nov 3 2010 4:52 AM

What is the correct way of datagridviewcomboboxcolumn bind with sql database and re- arrange with other column. Suppose if I have columns like below.

  1. Srno

  2. Particulars // this columns is for datagridviewcomboBoxColumn

  3. Amount.

I wants the datagridview's columns correct order as above and the same is for the purpose

of data entry.

Suppose if I have Following Dummy Table like

dummy

  1. Srno

  2. Particulars

  3. Amount.

MySqlConnection Code is as below.

 string cons = "server=.;initial catalog=maa;uid=mah;pwd=mah";
SqlConnection con = new SqlConnection(cons);
con
.Open();
string sql = "select particulars from dummy";
SqlDataAdapter dap = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
dap
.Fill(ds);
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb
.DataSource = ds.Tables[0];
cmb
.DisplayMember = "name";
cmb
.ValueMember = "name";
dataGridView1
.Columns.Add(cmb);

The above datagridviewcomboboxcolumn is set to dgv.columns[0] where as I wants the dgv

columns orders as below.

  1. Datagridview.columns[0] is for srno

  2. Datagridview.columns[1] is for Particulars   //For datagridviewcomboBoxColumn.

  3. Datagridview.columns[2] is for Amount

Note:- "I need the correct way to add all three columns in datagridview as above order"


Answers (3)