Hey guys, I have an application that I want to display some data from a sql db in a DataGridView... I have the data displayed in the DataGridView now but here are my questions..
For hiding you columns ("Row_ID") You can use
dgView.Columns[0].Visible = false;
For setting header text
dgView.Columns[1].HeaderText = "PartNumber";
If you want to use Custom titles etc. First of all create a new datatable, and give the names. Be Careful about typeof()
DataTable dt = new DataTable();
dt.Columns.Add("Title 1",typeof(int));
dt.Columns.Add("Title 2", typeof(string));
dt.Columns.Add("Title 3", typeof(DateTime));
dt.Columns.Add("Title 4", typeof(bool));
dt.AcceptChanges();
Get all data which comes from SQL and create object for them in
foreach(var item in yourSqlData)
object[] row = new object[]
{
item.data1.ToString(), // string columns
Convert.ToInt32(item.data2), // int columns
Convert.ToDateTime(item.data3), // datetime column
Convert.ToBoolean(item.data4) // bool column
};
dt.Rows.Add(row);
and bind dt to your gridView