resetting datagrid

  • Thread starter Thread starter codewriter
  • Start date Start date
C

codewriter

This will do:
this.dataGrid1.DataSource = null;

this.dataGrid1.Refresh();

"VM" <None> wrote in message How can I reset a datagrid? In my code, on an event, I do all the databinding of the datagrid to the dataset dynamically:

... //get the Dataset

DGOrders.SetDataBinding(DSMyTrans, "ClientTrans");
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "ClientTrans";
DataColProds.HeaderText = "Desc";
DataColProds.MappingName = "description";
ts1.GridColumnStyles.Add(DataColProds);
DGOrders.TableStyles.Add(ts1);
DataColProds.Width = 140;
myDataColItemNumber.HeaderText = "Item No.";
myDataColItemNumber.MappingName = "itemid";
ts1.GridColumnStyles.Add(myDataColItemNumber);
DGOrders.TableStyles.Add(ts1);
myDataColItemNumber.Width = 70;
...

What can I do so, when I click again, it erases/deletes all columns and data and regenerates it with the above code?
Thanks,
VM
 
How can I reset a datagrid? In my code, on an event, I do all the databinding of the datagrid to the dataset dynamically:

.... //get the Dataset

DGOrders.SetDataBinding(DSMyTrans, "ClientTrans");
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "ClientTrans";
DataColProds.HeaderText = "Desc";
DataColProds.MappingName = "description";
ts1.GridColumnStyles.Add(DataColProds);
DGOrders.TableStyles.Add(ts1);
DataColProds.Width = 140;
myDataColItemNumber.HeaderText = "Item No.";
myDataColItemNumber.MappingName = "itemid";
ts1.GridColumnStyles.Add(myDataColItemNumber);
DGOrders.TableStyles.Add(ts1);
myDataColItemNumber.Width = 70;
....

What can I do so, when I click again, it erases/deletes all columns and data and regenerates it with the above code?
Thanks,
VM
 
This did help but I have another problem...

Although it resets my datagrid, I can't add the same column to the datagrid (error: "The data grid table styles collection already contains a table style with the same mapping name."):
....

DGOrders.DataSource = null;

DGOrders.Refresh();

DGOrders.SetDataBinding(DSMyTrans, "ClientTrans");

ts1.MappingName = "ClientTrans";

DataColProds.HeaderText = "Desc";

DataColProds.MappingName = "description";

ts1.GridColumnStyles.Add(DataColProds);

DGOrders.TableStyles.Add(ts1); //error comes up here

DataColProds.Width = 140;

How come?
Thanks,

VM



This will do:
this.dataGrid1.DataSource = null;

this.dataGrid1.Refresh();

"VM" <None> wrote in message How can I reset a datagrid? In my code, on an event, I do all the databinding of the datagrid to the dataset dynamically:

... //get the Dataset

DGOrders.SetDataBinding(DSMyTrans, "ClientTrans");
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "ClientTrans";
DataColProds.HeaderText = "Desc";
DataColProds.MappingName = "description";
ts1.GridColumnStyles.Add(DataColProds);
DGOrders.TableStyles.Add(ts1);
DataColProds.Width = 140;
myDataColItemNumber.HeaderText = "Item No.";
myDataColItemNumber.MappingName = "itemid";
ts1.GridColumnStyles.Add(myDataColItemNumber);
DGOrders.TableStyles.Add(ts1);
myDataColItemNumber.Width = 70;
...

What can I do so, when I click again, it erases/deletes all columns and data and regenerates it with the above code?
Thanks,
VM
 
this usually works for me:

grid.SetDataBinding( null, "" );

----------------------------

"VM" <None> wrote in message How can I reset a datagrid? In my code, on an event, I do all the
databinding of the datagrid to the dataset dynamically:

.... //get the Dataset

DGOrders.SetDataBinding(DSMyTrans, "ClientTrans");
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "ClientTrans";
DataColProds.HeaderText = "Desc";
DataColProds.MappingName = "description";
ts1.GridColumnStyles.Add(DataColProds);
DGOrders.TableStyles.Add(ts1);
DataColProds.Width = 140;
myDataColItemNumber.HeaderText = "Item No.";
myDataColItemNumber.MappingName = "itemid";
ts1.GridColumnStyles.Add(myDataColItemNumber);
DGOrders.TableStyles.Add(ts1);
myDataColItemNumber.Width = 70;
....

What can I do so, when I click again, it erases/deletes all columns and data
and regenerates it with the above code?
Thanks,
VM
 
Back
Top