Thread: Taking data from DataGridView cells to add to a different DataGridView

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    73

    Taking data from DataGridView cells to add to a different DataGridView

    Working on a project involving the use of two datagridviews. The idea being that the user will select entries from one, hit a button, and it will add them to another. At the moment, I'm just trying to get one selected item to show up if added right. After that, I will work on looping. The code I tried is below. Returns OutOfRange exceptions when I run. How do I get it to properly store and add the values?

    Code:
    int selectedRowIndex = ResultList.SelectedCells[0].RowIndex;                DataGridViewRow selectedRow = ResultList.Rows[selectedRowIndex];
    
    
                    DataGridViewRow NewRow = new DataGridViewRow();
                    NewRow.Cells[0].Value = selectedRow.Cells[0].Value;
                    NewRow.Cells[1].Value = selectedRow.Cells[1].Value;
                    NewRow.Cells[2].Value = selectedRow.Cells[2].Value;
                    NewRow.Cells[3].Value = selectedRow.Cells[3].Value;
                    NewRow.Cells[4].Value = selectedRow.Cells[4].Value;
                    NewRow.Cells[5].Value = selectedRow.Cells[5].Value;
                    NewRow.Cells[6].Value = selectedRow.Cells[6].Value;
                    NewRow.Cells[7].Value = selectedRow.Cells[7].Value;
                    NewRow.Cells[8].Value = selectedRow.Cells[14].Value;
                    NewRow.Cells[9].Value = selectedRow.Cells[12].Value;
    
    
                    QueueView.Rows.Add(NewRow);

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    What line are you getting the error on? Have you tried using selectedRow.Cells.Add() instead of using the index directly?
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with printing datagridview
    By kemoox in forum C# Programming
    Replies: 1
    Last Post: 03-11-2011, 04:59 AM
  2. datagridview
    By darren78 in forum C# Programming
    Replies: 2
    Last Post: 11-16-2010, 05:43 PM
  3. DataGridView
    By sgh in forum C# Programming
    Replies: 1
    Last Post: 03-18-2009, 10:40 PM
  4. Newbie - Datagridview
    By spadez in forum C# Programming
    Replies: 1
    Last Post: 03-15-2009, 01:01 PM
  5. DataGridView Cant Get It To Display Text When I Tell It!
    By karimallen in forum C# Programming
    Replies: 1
    Last Post: 11-22-2007, 10:16 AM