C
ChrisM
Can anyone please tell me what I'm doing wrong here.
I have a Windows Form with a DataGrid on it, and I'm having real problems
with the Sorting.
It is easy to reproduce the problem I have.
If you create a new Windows Application
Put a DataGrid control on it.
Put the following in the onload event of the form:
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridTableStyle dgts = new DataGridTableStyle();
DataGridTextBoxColumn dgtbc1 = new DataGridTextBoxColumn();
DataGridTextBoxColumn dgtbc2 = new DataGridTextBoxColumn();
dgtbc1.Width = 300;
dgtbc1.HeaderText = "Header1";
dgts.GridColumnStyles.Add(dgtbc1);
dgtbc2.Width = 300;
dgtbc2.HeaderText = "Header2";
dgts.GridColumnStyles.Add(dgtbc2);
dataGrid1.TableStyles.Add(dgts);
DataTable dt = new DataTable("SuperTable");
dt.Columns.Add("One");
dt.Columns.Add("Two");
dataGrid1.DataSource = dt;
}
So by my understanding, I have created a tableStyle and added a couple of
textBoxColumns to it, then applied that style to my datagrid.
I have then created a DataTable, and made that the dataSource of my
dataTable.
If you run the app you should get an empty grid.
In Column1 put the letters a-h
In Column2 put the numbers 1-8
Click on the header of Column1 a couple of times so that the letters are
sorted a-h
Click on the 5 in Column2 and change it to 100.
Try clicking on the header of Column2 to sort the numbers correctly.
Why doesn't that work? The row with '100' in it stays in position, doesn't
get re-sorted.
Note: If you click on a few cells in the table, then it seems to sort itself
out,
but how can I re-produce that in code?
I'm sure that I've done somthing dumb, but I can't see it.
If anyone can cast light on this, I will be most grateful
Regards,
Chris.
I have a Windows Form with a DataGrid on it, and I'm having real problems
with the Sorting.
It is easy to reproduce the problem I have.
If you create a new Windows Application
Put a DataGrid control on it.
Put the following in the onload event of the form:
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridTableStyle dgts = new DataGridTableStyle();
DataGridTextBoxColumn dgtbc1 = new DataGridTextBoxColumn();
DataGridTextBoxColumn dgtbc2 = new DataGridTextBoxColumn();
dgtbc1.Width = 300;
dgtbc1.HeaderText = "Header1";
dgts.GridColumnStyles.Add(dgtbc1);
dgtbc2.Width = 300;
dgtbc2.HeaderText = "Header2";
dgts.GridColumnStyles.Add(dgtbc2);
dataGrid1.TableStyles.Add(dgts);
DataTable dt = new DataTable("SuperTable");
dt.Columns.Add("One");
dt.Columns.Add("Two");
dataGrid1.DataSource = dt;
}
So by my understanding, I have created a tableStyle and added a couple of
textBoxColumns to it, then applied that style to my datagrid.
I have then created a DataTable, and made that the dataSource of my
dataTable.
If you run the app you should get an empty grid.
In Column1 put the letters a-h
In Column2 put the numbers 1-8
Click on the header of Column1 a couple of times so that the letters are
sorted a-h
Click on the 5 in Column2 and change it to 100.
Try clicking on the header of Column2 to sort the numbers correctly.
Why doesn't that work? The row with '100' in it stays in position, doesn't
get re-sorted.
Note: If you click on a few cells in the table, then it seems to sort itself
out,
but how can I re-produce that in code?
I'm sure that I've done somthing dumb, but I can't see it.
If anyone can cast light on this, I will be most grateful
Regards,
Chris.