How to copy selected records from one Radgridview to another Radgridview in Vb. net

4 Answers 181 Views
GridView
Nandan
Top achievements
Rank 1
Iron
Iron
Iron
Nandan asked on 19 Jun 2023, 06:57 AM

Hi

I want to copy data from RadGridView1 to another RadGridView2.  I want to copy selected row from datagridview 1 using checkbox to another datagridview2. and selected rows should be removed from datagridview1.

And if i selected from datagridview2 it should moved again to datagridview1.

 

For Each row As GridViewDataRowInfo In Me.RadGridView1 .Rows
                  if  row.Cells(0).Value = true  then''Checkbox column

                 dim i as int16= Me.RadGridView2.add

                Me.RadGridView2.rows(i).cells(0).value= row.cells(0).vlaue.tostirng

         End If
Next row

 

 

vaibhavi
Top achievements
Rank 1
commented on 21 Jun 2023, 01:18 PM

Code not supported in my visual basic 2015 

please send me the simple form design and code

4 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 21 Jun 2023, 10:13 AM

Hello Nandan,

If the RadGridView is in the DataBound scenario, you can use the bound collections to transfer the checked row. For your convenience, I have created a sample project which demonstrates what I have in mind. For the checkbox, I have used GridViewCheckBoxColumn. To catch the moment when the user checks a checkbox, I have subscribed to the ValueChanged event on both RadGridViews. In the event handlers, I am transferring the row to the other bound collection.

You can find the sample project attached to this reply.

As a side note, the attached project does not contain our DLLs. Before running the project you need to add a reference to all required assemblies from your C:\Program Files (x86)\Progress installation folder.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 21 Jun 2023, 10:25 AM

Hi dinko

 

thanks for answer first raddatagridview 1 is databound and radgridview is not databound.

 

Regards

 

Nandan

0
Dinko | Tech Support Engineer
Telerik team
answered on 21 Jun 2023, 11:08 AM | edited on 23 Jun 2023, 12:50 PM

Hi Nandan,

In this case, you can use the Rows collection of the second and add a row to it. For this purpose, you can use the AddNew() method of the Rows collection, which adds a row and return it. What's left is to transfer the cell's value.

 

private void RadGridView1_ValueChanged(object sender, EventArgs e)
{
    if (this.radGridView1.ActiveEditor is RadCheckBoxEditor )
    {
        var rowForTransfer = this.radGridView1.SelectedRows.First();
        var item = rowForTransfer.DataBoundItem as MyItem;
        item.IsChecked = false;
        leftItems.Remove(item);
        var row = this.radGridView2.Rows.AddNew();
        row.Cells[0].Value = item.IsChecked;
        row.Cells[1].Value = item.Name;
    }
}
private void RadGridView2_ValueChanged1(object sender, EventArgs e)
{
    if (this.radGridView2.ActiveEditor is RadCheckBoxEditor && this.radGridView2.SelectedRows.Count > 0)
    {
        var rowForTransfer = this.radGridView2.SelectedRows.First();
        MyItem myItem = new MyItem();
        myItem.IsChecked = false;
        myItem.Name = rowForTransfer.Cells[1].Value.ToString();
        this.radGridView2.Rows.RemoveAt(rowForTransfer.Index);
            
        leftItems.Add(myItem);
    }
}  

 

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Dinko | Tech Support Engineer
Telerik team
answered on 23 Jun 2023, 12:53 PM

Hello Nandan,

As per your requirement in one of the posts above, I have converted my project to VB using our online Code Converter tool. You can find the project attached here.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 01 Jul 2023, 07:54 AM

Hi dinko

thanks for your timely help. Kindly resolve my problem 

 

Dim item = TryCast(rowForTransfer.DataBoundItem, dtdata)

            Dim data As DataRowView = TryCast(RadGridView1.CurrentRow.DataBoundItem, DataRowView)
            data.IsChecked = False
            dt.Remove(item)
            Dim row = Me.RadGridView2.Rows.AddNew()
            row.Cells(0).Value = item.IsChecked
            row.Cells(1).Value = item.Name

this code i want to replace with datatable

Private Function FetchAllDetails() As DataTable
        Try
            Dim parameters = New List(Of SqlParameter)()

            With parameters
                .Clear()
                .Add(dbManager.CreateParameter("@ActionType", "FetchData", DbType.String))
            End With

            dtData = dbManager.GetDataTable("SP_ItemMaster_Select", CommandType.StoredProcedure, parameters.ToArray())

        Catch ex As Exception
            MessageBox.Show("Error:- " & ex.Message)
        End Try

        Return dtData

    End Function

I am not aware about this coding

Private leftItems As BindingList(Of MyItem) = New BindingList(Of MyItem)()
Private rightItems As BindingList(Of MyItem) = New BindingList(Of MyItem)()

 

Regards

Nandan

 

0
Dinko | Tech Support Engineer
Telerik team
answered on 04 Jul 2023, 11:39 AM

Hello Nandan,

BindingList is a generic list type that has additional binding support. You can read more about it in the Binding to BindingList help article inside the RadGridView DataBinding section. If I have correctly understood your scenario, one of your RadGridViews is bound to a DataTable and the second is in unbound mode. I have modified my test project to demonstrate similar behavior with DataTable. You can find it attached to this reply.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Nandan
Top achievements
Rank 1
Iron
Iron
Iron
commented on 04 Jul 2023, 01:50 PM

Hi Dinko

Its work correctly just what I needed. Thanks again for understanding my  scenario.  I am going through link about Binding to Bindinglist.

Regards,

Nandan Navale

 

Tags
GridView
Asked by
Nandan
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or