Combine rows in a DataGrid

Posted on 2009-04-30
Last Modified: 2013-11-27
Hi Experts

I have a Datagrid(DataGridView1) which I use to populate a Access query. I want a user to be able to select two lines and then click on a button that combines the text from both lines together.
Lines   Discription

1     Discription_1
2     Discription_2

Lines   Discription

1      Discription_1 & Discription_2

Thanx in advance
Question by:Benvor
    LVL 48

    Accepted Solution

    You can try something like this to combine the strings:

            Dim result As String = String.Empty
            For Each cell As DataGridViewCell In Me.DataGridView1.SelectedCells
                result &= cell.Value.ToString & " & "
            Me.DataGridView1.SelectedCells(0).Value = result.Remove(result.Length - 2)

    Open in new window


    Author Closing Comment

    Thanx allot

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now