473,587 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid Datatable Insert rows and data

Rob
I am trying to copy some data from one datagrid to another. The first
datagrid containing data is called DocList. The blank Datagrid that I am
trying to copy some data to is called DataGrid1.

Please tell me the simplist way to loop through an existing datagrid, access
it's columns and rows, then copy parts of that data to a blank Datagrid1.

Thank you.

What I've tried unsuccessfully:
....
Dim dt As DataTable
Dim dr As DataRow
DataGrid1.DataS ource = dt

Dim DocListGridItem As DataGridItem
For Each DocListGridItem In DocList.Items
dr = dt.NewRow
dt.Rows.Add(dr)
dr.Item(0) = DocListGridItem .Cells(0).Text( )
Next
....
--
Rob
Nov 23 '05 #1
6 9222
Just create a second dataset 9(which I believe you already have) and then
call Merge on the dataset passing in the first as a parameter. But I would
ask, do you definitely need two different tables - if not, I'd be careful
their b/c of performance issues.
"Rob" <Ro*@discussion s.microsoft.com > wrote in message
news:4D******** *************** ***********@mic rosoft.com...
I am trying to copy some data from one datagrid to another. The first
datagrid containing data is called DocList. The blank Datagrid that I am
trying to copy some data to is called DataGrid1.

Please tell me the simplist way to loop through an existing datagrid,
access
it's columns and rows, then copy parts of that data to a blank Datagrid1.

Thank you.

What I've tried unsuccessfully:
...
Dim dt As DataTable
Dim dr As DataRow
DataGrid1.DataS ource = dt

Dim DocListGridItem As DataGridItem
For Each DocListGridItem In DocList.Items
dr = dt.NewRow
dt.Rows.Add(dr)
dr.Item(0) = DocListGridItem .Cells(0).Text( )
Next
...
--
Rob

Nov 23 '05 #2
Rob,

Because of the fact that the datagrid does not contain any data, can you set
the datasources of both datagrids to the same datatable.

If it has to be datafrom the same table however filtered than you can do

datagrid1.datas ource = dt.defaultview
dim dv2 as new dataview(dt)
dv.rowfilter = whatever
datagrid1.datas ource = dv2

If you want to show different columnst, than you use datagridcolumns tyles.

I hope this helps,

Cor
Nov 23 '05 #3
Rob
What I am trying to do is iterate through the first datagrid, which contains
essentially one column like a CSV string. Break it appart, one by one,
massage the data, then insert it into the second initially blank datagrid in
multiple columns row for row.

Do you happen to have a good example of this?

Thank you,

Rob

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:OV******** *****@TK2MSFTNG P15.phx.gbl...
Rob,

Because of the fact that the datagrid does not contain any data, can you set the datasources of both datagrids to the same datatable.

If it has to be datafrom the same table however filtered than you can do

datagrid1.datas ource = dt.defaultview
dim dv2 as new dataview(dt)
dv.rowfilter = whatever
datagrid1.datas ource = dv2

If you want to show different columnst, than you use datagridcolumns tyles.

I hope this helps,

Cor

Nov 23 '05 #4
Rob,

In my opinion is than to set an extra boolean column in your datatable

You can than use this column in the second dataview as a filter that shows
than the selected results in another datagrid/datagridview.

I made for you a sample on our website, can you try that?

http://www.vb-tips.com/default.aspx?...1-ac8b53818af6

I hope this helps,

Cor
Nov 23 '05 #5
Rob
Cor,

Thank you for the suggestion. Unfortunately I cannot convert to Visual
Studio 2005 and Ver 2.0 at this time. I am currently stuck in VS2003 ver
1.1, so I'm not aware how to make the Dataview help me at this time.

What I have tried unsuccessfully so far is with an error:

System.NullRefe renceException: Object reference not set to an instance of an
object
Line 104: Dim aNewRow As DataRow =
DsMain.Tables(" ToImport").NewR ow

'DocList is a Datagrid containing one column of Data seperated by a period.

Dim DsMain As New DataSet
DsMain.Tables.A dd("ToImport")
DsMain.Tables(" ToImport").Colu mns.Add("Col1")
DsMain.Tables(" ToImport").Colu mns.Add("Col2")
DsMain.Tables(" ToImport").Colu mns.Add("Col3")
DsMain.Tables(" ToImport").Colu mns.Add("Col4")
DsMain.Tables(" ToImport").Colu mns.Add("Col5")
DsMain.Tables(" ToImport").Colu mns.Add("Col6")
DsMain.Tables(" ToImport").Colu mns.Add("Col7")
DsMain.Tables(" ToImport").Colu mns.Add("Col8")
DsMain.Tables(" ToImport").Colu mns.Add("Col9")
DsMain.Tables(" ToImport").Colu mns.Add("Col10" )
DsMain.Tables(" ToImport").Colu mns.Add("Col11" )
Dim dt As DataTable
Dim dr As DataRow
Dim txt As String
Dim token As String
Dim DocListGridItem As DataGridItem
Dim tempint As Integer
For Each DocListGridItem In DocList.Items
Dim aNewRow As DataRow = DsMain.Tables(" ToImport").NewR ow
tempint = 0
aNewRow.Item(te mpint) =
GetToken(DocLis tGridItem.Cells (0).Text(), ".") & vbCrLf
Do
If tempint = 10 Then
tempint = 0
DsMain.Tables(" ToImport").Rows .Add(aNewRow)
Else
tempint = tempint + 1
End If
token = GetToken("", ".")
If token = "" Then Exit Do
txt = txt & token & vbCrLf
' create new row in the Main DataSet
aNewRow.Item(te mpint) = token
Loop
Next

' assigning the dataset object into the datagrid to accept the csv
data broken down into multiple columns
DataGrid1.DataS ource = DsMain
DataGrid1.DataB ind()
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:u7******** ******@TK2MSFTN GP10.phx.gbl...
Rob,

In my opinion is than to set an extra boolean column in your datatable

You can than use this column in the second dataview as a filter that shows
than the selected results in another datagrid/datagridview.

I made for you a sample on our website, can you try that?

http://www.vb-tips.com/default.aspx?...1-ac8b53818af6
I hope this helps,

Cor

Nov 23 '05 #6
Rob,

The sample should work for a datagrid as well, you would only have to use
styles to get the second grid nice.

I tested it now and saw I had to set that extra loop to set the boolean to
false, what was not needed in that datagridview sample, however basicly it
stays the same, however, in my opinion works a little bit nicer with the
datagridview, because that is pushed down direct with that commit. But that
you cannot reach in anyway with a datagrid.

\\\
Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
'Make the basic table
Dim dt As New DataTable
dt.Columns.Add( "Name")
dt.LoadDataRow( New Object() {"Ken"}, True)
dt.LoadDataRow( New Object() {"Cor"}, True)
dt.LoadDataRow( New Object() {"Peter"}, True)
DataGrid1.DataS ource = dt.DefaultView
'Adding the extra column
dt.Columns.Add( "Check", GetType(System. Boolean))
For Each dr As DataRow In dt.Rows
dr("check") = False
Next
'Make the selection
Dim dv As New DataView(dt)
dv.RowFilter = "Check = true"
DataGrid2.DataS ource = dv
End Sub

Private Sub DataGridView1_P aint(ByVal sender As Object, _
ByVal e As System.Windows. Forms.PaintEven tArgs) Handles DataGrid1.Paint
'Push the changes down to the datasource
BindingContext( DirectCast(Data Grid1.DataSourc e,
DataView)).EndC urrentEdit()
End Sub
///

I hope this helps,

Cor
Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12225
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. The ID is a member of the keys array. I then create a DataView dv over the table, and sort it by Display and ID column (in case of duplicate Display). I then set my DataGrid.DataSource = dv; I then load the datatable with my rows, and this is...
4
5347
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. Currently everything is working. I can find the updated rows/columns by parsing the posted data collection against the DataGrid DataSource. However, when there is a large amount of DataGridItems (rows) the update processing can take a while. ...
8
1933
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a button that inserts a new row in the SQL table and then refresh the datagrid.
1
3268
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
4
3487
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a snippet from my .css file: *************************** body { margin:0; padding:0;
8
2020
by: Strahimir Antoljak | last post by:
I bound a DataGrid to a table (I tried with a DataView too). I removed the row from the table, and then inserted a new row at the same row index. the table gets the row to the right position, but the bound DataGrid does not pick up and appends the inserted row at the bottom of the grid, not the right position?!? Any ideas how to make the DataGrid pick up the changes done in the table - to show the inserted row at the right position?
0
1925
by: Matt | last post by:
I derived my own custom class from the datagrid class. I overrode the ProcessCmdKey Function, like this, to catch the up and down arrow keys: ====== Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean Const WM_KEYDOWN As Integer = &H100
0
1181
by: Freddie | last post by:
hi, i need a datagrid w/ 2 headers, the datagrid is bound if( ! IsPostBack), Ken Cox kindly shared some code that addes a new header in the ItemDataBound method, so i moved it to Page_Load, and now the last row of datagrid disappears on postback - i.e. all item rows disappera after a few postacks so far i found only this:
6
3700
by: rcoco | last post by:
Hi, I have a datagrid that is ment to insert data. But when I run the form only the header appears. I would like some advise from you all and solve this problem I'm using visual studio 2003. My code looks like this: private void Fill() { DataTable table = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from
0
1381
by: rcoco | last post by:
Hi, Ihave a datagrid that Insert data in some rows. One column has RadioButtonList that contains three Items. But When I select one radiobuton, insert data in other columns and select insert data The radio button unselects itself. Why would this be happening? here is my code. DataTable table = new DataTable(); private DataTable Fill() {
0
8219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.