datagrid copy rows

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

    #1

    datagrid copy rows

    Hello Group,
    I have 2 datagrids and the first one is bound to a
    database. Each row consists of checkbox, textbox etc.. As the user makes
    the selection, I want to add the corresponding row to the other datagrid.
    Unable to figure out how to copy rows in DG. Any help would be appreciated!

    Thanks,
    Chris.


  • Kevin Yu [MSFT]

    #2
    RE: datagrid copy rows

    Hi Chris,

    First of all, I would like to confirm my understanding of your issue. From
    your description, I understand that you need to add rows from one DataGrid
    to the other. If there is any misunderstandin g, please feel free to let me
    know.

    Generally, when we need to add rows from one DataGrid to the other, we have
    to add rows in the source DataSet. Here is an example. when you click a row
    on one DataGrid, that row will be added to the other DataGrid.

    private void Form1_Load(obje ct sender, System.EventArg s e)
    {
    SqlDataAdapter sda = new SqlDataAdapter( "SELECT * FROM Employees",
    this.sqlConnect ion1);
    this.ds1 = new DataSet();
    this.ds2 = new DataSet();
    sda.FillSchema( ds1, SchemaType.Sour ce);
    sda.FillSchema( ds2, SchemaType.Sour ce);
    sda.Fill(ds1);
    this.dataGrid1. DataSource = ds1.Tables[0];
    this.dataGrid2. DataSource = ds2.Tables[0];

    cm = (CurrencyManage r)this.BindingC ontext[this.ds1.Tables[0]];
    cm.CurrentChang ed +=new EventHandler(cm _CurrentChanged );
    }

    private void cm_CurrentChang ed(object sender, EventArgs e)
    {

    this.ds2.Tables[0].Rows.Add(this. ds1.Tables[0].Rows[this.cm.Positio n].ItemAr
    ray);
    }

    HTH. If anything is unclear, please feel free to reply to the post.

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."

    Comment

    • sam

      #3
      Re: datagrid copy rows

      I should have mentioned that I am talking in the context of web data
      grid.
      The idea seems to be clear and I am trying to incorporate the same but
      any sample code(asp.net/vb.net) could be appreciated!

      Thanks,
      Chris.

      v-kevy@online.mic rosoft.com (Kevin Yu [MSFT]) wrote in message news:<C4a3Q2BWE HA.4088@cpmsftn gxa10.phx.gbl>. ..[color=blue]
      > Hi Chris,
      >
      > First of all, I would like to confirm my understanding of your issue. From
      > your description, I understand that you need to add rows from one DataGrid
      > to the other. If there is any misunderstandin g, please feel free to let me
      > know.
      >
      > Generally, when we need to add rows from one DataGrid to the other, we have
      > to add rows in the source DataSet. Here is an example. when you click a row
      > on one DataGrid, that row will be added to the other DataGrid.
      >
      > private void Form1_Load(obje ct sender, System.EventArg s e)
      > {
      > SqlDataAdapter sda = new SqlDataAdapter( "SELECT * FROM Employees",
      > this.sqlConnect ion1);
      > this.ds1 = new DataSet();
      > this.ds2 = new DataSet();
      > sda.FillSchema( ds1, SchemaType.Sour ce);
      > sda.FillSchema( ds2, SchemaType.Sour ce);
      > sda.Fill(ds1);
      > this.dataGrid1. DataSource = ds1.Tables[0];
      > this.dataGrid2. DataSource = ds2.Tables[0];
      >
      > cm = (CurrencyManage r)this.BindingC ontext[this.ds1.Tables[0]];
      > cm.CurrentChang ed +=new EventHandler(cm _CurrentChanged );
      > }
      >
      > private void cm_CurrentChang ed(object sender, EventArgs e)
      > {
      >
      > this.ds2.Tables[0].Rows.Add(this. ds1.Tables[0].Rows[this.cm.Positio n].ItemAr
      > ray);
      > }
      >
      > HTH. If anything is unclear, please feel free to reply to the post.
      >
      > Kevin Yu
      > =======
      > "This posting is provided "AS IS" with no warranties, and confers no
      > rights."[/color]

      Comment

      • Kevin Yu [MSFT]

        #4
        Re: datagrid copy rows

        Hi Chris,

        In an ASP.NET senario, we can use the same idea to add row values, except
        handling the CurrentChanged event and using CurrencyManager . We can use a
        button to fire the event and search for checked rows to add.

        Kevin Yu
        =======
        "This posting is provided "AS IS" with no warranties, and confers no
        rights."

        Comment

        Working...