Problem with DataGrid Headers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've a dataGrid, and When I click with the mouse on one of it's header the
DataGrid_Click event is called. I don't have problem with the event, but
strange things happen to the dataGrid after I click on one of the headers. I
have DataSet that bounded to this DataGrid so i could write into the
dataGrid, but when i click on the headers new rows are suddenly added,
sometime as a first row, sometimes between two exsisting rows. I change the
value of AllowSorting and AllowNavagtion to false, and still same problem.

How can I prevent that?

Thanks,
Gidi.
 
If this posts twice, my apologies as it appears the site had a problem earlier.

What are you using as the DataSource for your DataGrid? If you are using
the DataSet you may be seeing a "refreshed" version for some reason. If you
use a DataView instead, you should not see any updates unless you repopulate
the DataView explictly.

HTH
 
Hi,

The dataSet is used only for adding new rows, and to sign events to some
cells. when i click on the dataGrid's headers i see a little arrow (like when
you press it for sorting), that's what i want to make sure won't happen.

Thanks,
Gidi.
 
Ok, if all you are trying to do is disable the sorting capability on the
headers, in your DataStyles you can set the AllowSorting property to false:

private void ConfigureTestPointDatagrid()
{
DataGridTableStyle tsTP = new DataGridTableStyle();
tsTP.MappingName = "TestPoints Table";
tsTP.AlternatingBackColor = SystemColors.Control;
tsTP.AllowSorting = false;

/* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */
//Code to ID and format each column goes here THEN

testPointDatagrid.TableStyles.Add(tsTP);

HTH
 
Back
Top