copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid
copy row from datagrid to another datagrid copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
Go Back  Xtreme Visual Basic Talk > > > copy row from datagrid to another datagrid


Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2004, 12:50 PM
dirtebird dirtebird is offline
Newcomer
 
Join Date: Sep 2004
Location: Illinois
Posts: 10
Default copy row from datagrid to another datagrid


I am trying to copy a row from one datagrid to another, using the DataTables that they are each bound to, like so:

DataTable2.ImportRow(DataTable1.Rows(intSelectedRow))

DataTable2 is the Datasource for the Datagrid to be copied to.
DataTable1 is the Datasource for the Datagrid to be copied from.

DataTable1 is filled from a database, but DataTable2 is just a generic instance of a DataTable. When the above code executes, the row is added to DataTable2, but only a blank gridline shows up in the 2nd Datagrid. Can anybody help me out here?

On a somewhat related note, is there a control like the datagrid in .NET that doens't have to be bound to a datasource? I could accomplish what I need to do here in about 5 minutes with the VB6 flexgrid.
Reply With Quote
  #2  
Old 09-12-2004, 07:32 PM
MKoslof's Avatar
MKoslofcopy row from datagrid to another datagrid MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

A Datagrid can serve as an unbound source. Basically the ONLY thing that a datagrid needs in order to populate is:

- A single dimension array
- Any component that implements the IListSource interface
- Any component that implements the IList interface

Basically, you can create an array of data and assign the DataGrid this as your source. You can build a DataTable within your .Net interface (not from any bound table) and use this for your .DataSource. You can use an arraylist, etc. It is actually quite flexible.

How are you defining the datasources for your grids? Basically, if you want to copy a row from one DataGrid to another, just build the other datagrid's datasource on the fly or append the value to its existing datasource. Basically the value you receive from the DataTable1.Rows(intSelectedRow) can be put into an array, or added as a new value within an existing dataTable or new dataTable..then just assign this to the Datagrid in question.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 09-13-2004, 08:58 PM
dirtebird dirtebird is offline
Newcomer
 
Join Date: Sep 2004
Location: Illinois
Posts: 10
Default

MKoslof,

Thank you for the quick response.

In my above example, DataTable2 is the datasource for the datagrid that I want to copy into. When I copy the row from the first DataTable into DataTable2, however, nothing shows up in the datagrid but a new blank row(no columns or data of any kind). I have attached a screenprint of what the datagrid looks like before and after, if that will help clarify what I'm trying to say.

Any ideas on what I might be doing wrong?
Attached Images
File Type: jpg DataGridBefore.JPG (2.4 KB, 14 views)
File Type: jpg DataGridAfter.JPG (2.6 KB, 9 views)
Reply With Quote
  #4  
Old 09-14-2004, 05:53 PM
MKoslof's Avatar
MKoslofcopy row from datagrid to another datagrid MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Can you post the actual code you are implementing..especially where you try to send the new record to the other grid?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #5  
Old 09-14-2004, 06:39 PM
dirtebird dirtebird is offline
Newcomer
 
Join Date: Sep 2004
Location: Illinois
Posts: 10
Default

sure.

'This is where I Add the DataTable to the DataSet
objDataSet1.Tables.Add(objDataTable1)

'This is where I set the Datasource of the Datagrid to be populated
dgCarList1.DataSource = objDataSet1.Tables(0)

'This is where I copy a row from one datagrid's datasource to the new datasource
objDataTable1.ImportRow(objDataTable.Rows(intSelectedRow))


I also should add that in debug mode, after I execute the ImportRow command, the objDataTable1.Rows.count = 1, but objDataTable1.Columns.Count = 0. This is probably where the problem lies. So how do I add columns to a DataTable? Do I have to give them a data type when I do add them?

Last edited by dirtebird; 09-14-2004 at 06:48 PM.
Reply With Quote
  #6  
Old 09-14-2004, 07:19 PM
dirtebird dirtebird is offline
Newcomer
 
Join Date: Sep 2004
Location: Illinois
Posts: 10
Default

Nevermind I finally solved it. Here's what I did:

objDataTable1 = objDataTable.Clone

That got me the columns I needed for the new Table. After that, the importrow did it's thing and the new row showed up in the new datagrid!

Now I have a lot of formatting to take care of, but at least the data is there!

MKoslof, thanks for the time attention you gave to this thread, I appreciate that.
Reply With Quote
  #7  
Old 09-14-2004, 07:49 PM
MKoslof's Avatar
MKoslofcopy row from datagrid to another datagrid MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

No problem, glad you figured it out. Let us know if you need more assistance.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
 
copy row from datagrid to another datagrid
copy row from datagrid to another datagrid
 
-->