code to add dynamic data
getdata()
{
SqlConnection con = new SqlConnection("Data source=XXXXX;Initial catalog=dummy;integrated security=true");
DataTable dt = new DataTable();
DataColumn col = new DataColumn("Title", typeof(System.String));
dt.Columns.Add(col);
DataRow row = dt.NewRow();
con.Open();
SqlCommand cmd = new SqlCommand("select Title,Description from systemtray", con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
string s=dr["Title"].ToString()+Environment.NewLine+dr["Description"].ToString();
row["Title"]= s.Trim();
dt.Rows.Add(row["Title"]);
}
dataGridView1.DataSource = dt;
}
and i add two buttons to datagrid using properties.Here the out put is:two buttons are displaying at index [0],[1] and the data is displaying at last column,i need to display the data at index[0] position then two buttons.how can i set index manually.
From a Form Designer add new
DataGridViewTextBoxColumnand move it to top most position or at whatever position you would like to display this column at, then in properties of thisDataGridViewTextBoxColumnsetDataPropertyNameto the name of your column, which from your code, i can see that is Title, that’s it, compile, run and it should display the text column before button columns… I have attached a screenshot for you, I hope it will solve your problem…