Multiselection and copy-paste

crisagmail

New member
Joined
Apr 2, 2006
Messages
4
Programming Experience
1-3
Hi,

I need help with Visual Basic .NET datagrid control.
I have two datagrid’s control and one button. I want to select more than one row in the datagrid1 and when I press then button I want to copy this selected rows into a datagrid2.

1) How Can I Selected more than one row in a datagrid1? By default, I only can select one row.
2) How can I write into datagrid2 rows which don’t come from database. I would like to write the rows myself.


I hope your requests, please.

Thanks.

Cristina
 
Why not use the DataGridView control?
 
I need that data in the datagrid2 can be modified.
If I use datagridview control I think that data can't be modified.

Perhaps, I can use dataview control to data which are in datagrid1 now.
 
I can't use datagridview control??

Oh,

I didn't know this control. I confused dataview control with datagridview control.

But ... I have another problem, now. For using datagrid view control I need Framework v.2.0, so I have installed it but I can't put the reference at system.windows.forms.dll because MVS .NET 2003 don't let me. Perhaps I need MVS .NET 2005 to do it and use datagridview control. Is it true?
 
Yes .Net 2.0 can only be used in VS 2005. Wasn't your profile .Net2.0 yesterday? ;)
 
Ok, I have an Idea. I have some code I use to copy selected cells to the clipboard to be able to paste into Excel.
VB.NET:
        If e.KeyCode = Keys.F4 Then
            Dim strTemp As String   'string to be copied to the clipboard
            Dim row As Integer
            Dim col As C1.Win.C1TrueDBGrid.C1DataColumn
            Dim cols As Integer, rows As Integer
            If Me.PartGrid.SelectedRows.Count > 0 Then
                For Each row In Me.PartGrid.SelectedRows
                    'copy everything here
                    For Each col In Me.PartGrid.SelectedCols
                        strTemp = strTemp & col.CellText(row) & vbTab
                    Next
                    strTemp = strTemp & vbCrLf
                Next
                System.Windows.Forms.Clipboard.SetDataObject(strTemp, False)
                MessageBox.Show("Range of " & Me.PartGrid.SelectedCols.Count & " x " & PartGrid.SelectedRows.Count & " cells have been copied to the clipboard for Excel.")
            Else
                MessageBox.Show("Please select a range of cells")
            End If
        End If
This was written for a 3rd party DataGrid (ComponentOne TrueDBGrid) but it might give you some ideas. Mainly build a string with the values then tear it apart to put it into the new grid.

Hope that helps...
 
:D. John you are in true I changed to v1 MS 2003 today becuse I realised that v2 2005 isn't true...

Perhaphs I have to change the strategy for doing it. I'm thinking that I can use the listview control for doing that I need... despite doing more code than datagrid/datagridview control/s.

Thanks all.
 
Back
Top