473,704 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Copy/Paste existing row to a new row in data grid

Is there any way to copy an entire row from the Data Grid and then Paste it
into a new row, modify some data and then save it back to the database?

This grid is bound to a dataadapter with a commandbuilder monitoring the
activity.

Is there some property setting that needs to be set or what?
Nov 21 '05 #1
6 2366
Darrel,

Your datagrid is only showing data in the daatatable, often while there are
filters in between as the dataview for the rows or the datatablestyle for
the columns.

However the datatable is the point you have to look for.

If you don't know how to get a currentrow, than reply where you show than
the row of the datasource, and tell what that is.

The newrow should at least have a proper new primary key to be able to add
it to the database.

I hope this helps?

Cor
Nov 21 '05 #2
"Darrell Wesley" <Da***********@ discussions.mic rosoft.com> wrote in message
news:9B******** *************** ***********@mic rosoft.com...
Is there any way to copy an entire row from the Data Grid and then Paste
it
into a new row, modify some data and then save it back to the database?

This grid is bound to a dataadapter with a commandbuilder monitoring the
activity.

Is there some property setting that needs to be set or what?

The following code does this sort of thing, I was pushed for time when I
wrote it so it may not be particularly elegant. It does work..
============
Private Sub btnCopy_Click(B yVal o As Object, ByVal e As
System.EventArg s) Handles btnCopy.Click
' This is quite tricky...
' EG you need a unique label for a bucket rule
' Then.... how about if the user gets to see the thing he just
appended
' and you can't just stick the data in the tentative add row,
oh no...
If dsBucket_Rules. HasChanges() Then
MsgBox("Please update your outstanding changes before copying")
Exit Sub
End If

Dim al As New ArrayList
Dim cm As CurrencyManager =
Me.BindingConte xt(Me.grdBucket _Rules.DataSour ce,
Me.grdBucket_Ru les.DataMember)
Dim i As Integer
Dim FromRow As Integer
Dim dv As DataView = CType(cm.List, DataView)
For i = 0 To dv.Count - 1
If Me.grdBucket_Ru les.IsSelected( i) Then
al.Add(i)
FromRow = i
End If
Next i
If al.Count < 1 Then
MsgBox("You must select a row first")
Exit Sub
End If
If al.Count > 1 Then
MsgBox("You can only copy one row at a time." & vbCrLf & "This
is because description must be unique when you leave a row.")
Exit Sub
End If
Dim numRows As Integer =
Me.grdBucket_Ru les.BindingCont ext(Me.grdBucke t_Rules.DataSou rce,
Me.grdBucket_Ru les.DataMember) .Count

cm.EndCurrentEd it()

'Use the NewRow to create a DataRow in the DataSet
Dim myrow As DataRow = dsBucket_Rules. Tables(0).NewRo w()

myrow("Descript ion") = "** Copied Rule **"
myrow("Process_ On") = Me.grdBucket_Ru les.Item(FromRo w, 1)
myrow("ProductL ine") = Me.grdBucket_Ru les.Item(FromRo w, 2)
myrow("SiteStag e") = Me.grdBucket_Ru les.Item(FromRo w, 3)
myrow("Site") = Me.grdBucket_Ru les.Item(FromRo w, 4)
If Me.grdBucket_Ru les.Item(FromRo w, 5) = False Then
myrow("LOF") = "N"
Else
myrow("LOF") = "Y"
End If
If Me.grdBucket_Ru les.Item(FromRo w, 6) = False Then
myrow("Special" ) = "N"
Else
myrow("Special" ) = "Y"
End If
If Me.grdBucket_Ru les.Item(FromRo w, 7) = False Then
myrow("Membrane ") = "N"
Else
myrow("Membrane ") = "Y"
End If
myrow("Dimensio n") = Me.grdBucket_Ru les.Item(FromRo w, 8)
myrow("Dimensio n_From") = Me.grdBucket_Ru les.Item(FromRo w, 9)
myrow("Dimensio n_To") = Me.grdBucket_Ru les.Item(FromRo w, 10)
myrow("Qty_Fact or") = Me.grdBucket_Ru les.Item(FromRo w, 11)
myrow("Qty_Add" ) = Me.grdBucket_Ru les.Item(FromRo w, 12)
myrow("Qty_Cap_ In") = Me.grdBucket_Ru les.Item(FromRo w, 13)
myrow("Warp_Set ") = Me.grdBucket_Ru les.Item(FromRo w, 14)
Try
dsBucket_Rules. Tables(0).Rows. Add(myrow)
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
' Avoid concurrency errors from btnUpdate
myrow.EndEdit()
cm.EndCurrentEd it()
cm.Refresh()
' move to the newly added row
cm.Position = cm.Count - 1
btnCopy.Visible = False
End Sub
=============
Private Sub grdBucket_Rules _MouseUp(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles grdBucket_Rules .MouseUp
' Hide the copy button if they have not selected a row
Dim pt = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTes tInfo = grdBucket_Rules .HitTest(pt)
If hti.Type = DataGrid.HitTes tType.RowHeader Then
btnCopy.Visible = True
Else
btnCopy.Visible = False
End If
End Sub
=========
--
Regards,
Andy O'Neill
Nov 21 '05 #3
Cor and Andy,

I know that I can copy data out of any row that I click on but why can I not
do a simple paste into the newrow of the datagrid? I was hoping that it was
something that I was overlooking.

Why doesn't the data grid allow a paste of an entire row? It has a new row
entry at the bottom and you can certainly type data into it and then post it
back to the database but why won't a simple paste work?

"Cor Ligthert" wrote:
Darrel,

Your datagrid is only showing data in the daatatable, often while there are
filters in between as the dataview for the rows or the datatablestyle for
the columns.

However the datatable is the point you have to look for.

If you don't know how to get a currentrow, than reply where you show than
the row of the datasource, and tell what that is.

The newrow should at least have a proper new primary key to be able to add
it to the database.

I hope this helps?

Cor

Nov 21 '05 #4
Darrel,
Why doesn't the data grid allow a paste of an entire row? It has a new row
entry at the bottom and you can certainly type data into it and then post
it
back to the database but why won't a simple paste work?

I thought that I wrote that?

To what do you want to paste when it is set by a datagridtablest yle and all
values are from another type?

Cor
Nov 21 '05 #5
The datagrid is showing data from a single dataset and there is only one
table in the dataset. What I want to do "simply" is to copy an entire
row(Control-C will do this and you can paste the data into Notepad) and paste
it into the new row area of the grid - change the values that need to be
changed and then post it back to the underlying database. This would be just
like you can do in Access or Excel, but it doesn't appear to have paste
functionality for an entire row only for an individual cell.

"Cor Ligthert" wrote:
Darrel,
Why doesn't the data grid allow a paste of an entire row? It has a new row
entry at the bottom and you can certainly type data into it and then post
it
back to the database but why won't a simple paste work?

I thought that I wrote that?

To what do you want to paste when it is set by a datagridtablest yle and all
values are from another type?

Cor

Nov 21 '05 #6
Darrel,

Beside if it is possible, a datagrid is not office.

However what you want to do with the primary key?

Just creating a little button or menu item or context menu with copynew,
does in my opinion the same as that while you now let your users first copy
it and than paste it because that is the way it is done in office.

Cor
Nov 21 '05 #7

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

Similar topics

3
32944
by: Faith | last post by:
Hello. I need to take a column from Excel(unknown amount of rows) that will be selected by the user and copy those cells. Then I will need to paste those cells into the first column in a Data Grid (system.windows.forms). Basically, the user receives a list of clientIDs from a client as an email attachment in Excel listed like: 1234 ABC Company 234 DEF Company 348 GHI Company
7
11626
by: lgbjr | last post by:
Hello All, I°Įm using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
5
1462
by: kirschpe | last post by:
I developed an application using visual studio 2003. Now I want to make a similar application without having to redesign similar forms. Is there a way to copy and paste windows forms across application? I can copy from one to the paste buffer. BUT, there is no corresponding paste on the second application. How can you do this??? tia...
0
1239
by: Tom | last post by:
I need to be able to copy and paste data from an Excel spreadsheet to a grid or something to a web form and then save it to the database. example: if my spreadsheet has 20 rows of data I need to be able to copy all 20 rows of data and paste them to a grid or something to on my web form and save it. I can't copy the data line by line or cell by cell, I need to be able to do Select ALL copy then paste. is there anyway or anything to allow...
1
1206
by: veera372 | last post by:
i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard option... but i dont know java script... can anyone help me?
2
2500
by: veera372 | last post by:
hi this is veera, i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard option... but i dont know java script... can anyone help me?
1
2362
by: veera372 | last post by:
hi this is veera, i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard option... but i dont know java script... can anyone help me?
0
1046
by: veera372 | last post by:
hi this is veera, i wants to copy a data from an excel and paste it into a data grid in the web form (asp .net) by clicking the button paste... i think it can be done in java script using clipboard option... but i dont know java script... can anyone help me?
2
2780
by: OfficeDummy | last post by:
Hi, everyone! Like I mentioned in the thread title, I need to copy&paste data between different workbooks, and it works fine. However, when the data has been copied to the destination workbook, the grid disappears. Why, and how can I get it back? Thanks a lot in advance! Best, OfficeDummy
0
8764
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8677
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9130
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
9020
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
8974
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
4435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3130
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
2
2468
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2074
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.