resetting datagrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VM

    #1

    resetting datagrid

    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.SetDat aBinding(DSMyTr ans, "ClientTran s");
    DataGridTableSt yle ts1 = new DataGridTableSt yle();
    ts1.MappingName = "ClientTran s";
    DataColProds.He aderText = "Desc";
    DataColProds.Ma ppingName = "descriptio n";
    ts1.GridColumnS tyles.Add(DataC olProds);
    DGOrders.TableS tyles.Add(ts1);
    DataColProds.Wi dth = 140;
    myDataColItemNu mber.HeaderText = "Item No.";
    myDataColItemNu mber.MappingNam e = "itemid";
    ts1.GridColumnS tyles.Add(myDat aColItemNumber) ;
    DGOrders.TableS tyles.Add(ts1);
    myDataColItemNu mber.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

  • codewriter

    #2
    Re: resetting datagrid

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

    this.dataGrid1. Refresh();

    "VM" <None> wrote in message news:%23xv4sKgW DHA.1736@TK2MSF TNGP10.phx.gbl. ..
    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.SetDat aBinding(DSMyTr ans, "ClientTran s");
    DataGridTableSt yle ts1 = new DataGridTableSt yle();
    ts1.MappingName = "ClientTran s";
    DataColProds.He aderText = "Desc";
    DataColProds.Ma ppingName = "descriptio n";
    ts1.GridColumnS tyles.Add(DataC olProds);
    DGOrders.TableS tyles.Add(ts1);
    DataColProds.Wi dth = 140;
    myDataColItemNu mber.HeaderText = "Item No.";
    myDataColItemNu mber.MappingNam e = "itemid";
    ts1.GridColumnS tyles.Add(myDat aColItemNumber) ;
    DGOrders.TableS tyles.Add(ts1);
    myDataColItemNu mber.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

    Comment

    • VM

      #3
      Re: resetting datagrid

      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.DataSo urce = null;

      DGOrders.Refres h();

      DGOrders.SetDat aBinding(DSMyTr ans, "ClientTran s");

      ts1.MappingName = "ClientTran s";

      DataColProds.He aderText = "Desc";

      DataColProds.Ma ppingName = "descriptio n";

      ts1.GridColumnS tyles.Add(DataC olProds);

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

      DataColProds.Wi dth = 140;

      How come?
      Thanks,

      VM



      "codewriter " <code_writer_20 03@yahoo.com> wrote in message news:%gfXa.321$ pq5.101249@news 20.bellglobal.c om...
      This will do:
      this.dataGrid1. DataSource = null;

      this.dataGrid1. Refresh();

      "VM" <None> wrote in message news:%23xv4sKgW DHA.1736@TK2MSF TNGP10.phx.gbl. ..
      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.SetDat aBinding(DSMyTr ans, "ClientTran s");
      DataGridTableSt yle ts1 = new DataGridTableSt yle();
      ts1.MappingName = "ClientTran s";
      DataColProds.He aderText = "Desc";
      DataColProds.Ma ppingName = "descriptio n";
      ts1.GridColumnS tyles.Add(DataC olProds);
      DGOrders.TableS tyles.Add(ts1);
      DataColProds.Wi dth = 140;
      myDataColItemNu mber.HeaderText = "Item No.";
      myDataColItemNu mber.MappingNam e = "itemid";
      ts1.GridColumnS tyles.Add(myDat aColItemNumber) ;
      DGOrders.TableS tyles.Add(ts1);
      myDataColItemNu mber.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

      Comment

      • Gregory Persson

        #4
        Re: resetting datagrid

        this usually works for me:

        grid.SetDataBin ding( null, "" );

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

        "VM" <None> wrote in message news:#xv4sKgWDH A.1736@TK2MSFTN GP10.phx.gbl...
        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.SetDat aBinding(DSMyTr ans, "ClientTran s");
        DataGridTableSt yle ts1 = new DataGridTableSt yle();
        ts1.MappingName = "ClientTran s";
        DataColProds.He aderText = "Desc";
        DataColProds.Ma ppingName = "descriptio n";
        ts1.GridColumnS tyles.Add(DataC olProds);
        DGOrders.TableS tyles.Add(ts1);
        DataColProds.Wi dth = 140;
        myDataColItemNu mber.HeaderText = "Item No.";
        myDataColItemNu mber.MappingNam e = "itemid";
        ts1.GridColumnS tyles.Add(myDat aColItemNumber) ;
        DGOrders.TableS tyles.Add(ts1);
        myDataColItemNu mber.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


        Comment

        Working...