Hello experts,
I am using a Datagridview and a collection. My goal is
to fill the datagridview with data from a collection.
Though it appears easy enough to do it, however I noticed
that the columns do not appear in the order I wish them to be.
The code looks like this:
public void loadEntries()
{
// get the collection (all are strings)
List<StringHolder> logs = service.doGetTSRLogs();
if (logs != null)
{
// Remove auto-generated columns.
gvTSR.Columns.Clear();
// Make a bold header:
DataGridViewCellStyle style =
gvTSR.ColumnHeadersDefaultCellStyle;
style.Font = new Font(gvTSR.Font, FontStyle.Bold);
// Define header text:
gvTSR.Columns.Add("Env", "Env");
gvTSR.Columns[0].DataPropertyName = "shEnv";
... // more columns
gvTSR.Columns.Add("ReleaseDate", "ReleaseDate");
gvTSR.Columns[7].DataPropertyName = "shReleaseDate";
gvTSR.Columns.Add("ReleaseNo", "ReleaseNo");
gvTSR.Columns[8].DataPropertyName = "shReleaseNo";
gvTSR.Columns.Add("CreatedDate", "CreatedDate");
gvTSR.Columns[9].DataPropertyName = "shCreatedDate";
gvTSR.DataSource = logs;
}
}
When run, I expect the columns appears in this order:
Env ....more columns... ReleaseDate ReleaseNo CreatedDate
But I got this instead:
Env ....more columns... ReleaseDate CreatedDate ReleaseNo
I checked my "beans"(class with getters and setters), and they all
even coded in a correct order as I intend them to be.
But when I run the program, the "CreatedDate" always appear to
be between ReleaseDate and ReleaseNo even if I *explicitly*
defined that the CreatedDate column *must* appear in the 9th
index/column (or [9]). Note that all these fields are strings.
Can someone help? Is this a bug from the datagridview itself?
Thanks in advance.