I have a datagridview in my project that populates from an SQL database with the following code:
public cToDoList(string paramUser, DateTime paramDueDate) { string sqlStat = "SELECT * FROM tblDiary " + "WHERE DiaryUserFor = @User " + "AND DiaryDueDate <= @DueDate;"; SqlCommand sqlCom = new SqlCommand(sqlStat); sqlCom.Parameters.Add("@User", SqlDbType.VarChar); sqlCom.Parameters.Add("@DueDate", SqlDbType.Date); sqlCom.Parameters["@User"].Value = paramUser; sqlCom.Parameters["@DueDate"].Value = paramDueDate.Date; cSqlQuery sqlQ = new cSqlQuery(sqlCom, "table"); this.cTable = sqlQ.cQueryResults; }
The above code works fine and the datagridview fills up, however the column headers are field names from the SQL database which are not very user friendly.
I tried a couple of things to try changing the default column names, but nothing works. While I tried -
dataToDoList.Columns[0].Name = "TEST1"; dataToDoList.Columns["DiaryCompletedDate"].Name = "TEST2";
But do nothing.
Can someone tell me how to change column header names in datagridview please?
source share