Help with loading control based on idemtical columns headings in two DBGrids

Posted by: Victor.m.charles.civ on 25 February 2020, 6:58 pm EST

    • Post Options:
    • Link

    Posted 25 February 2020, 6:58 pm EST

    Hi,

    How do I compare the caption between two Grids and only display matching columns in my C1MultiSelect control?

    Below is code to load the control directly from one Grid control.

    For i As Integer = 0 To C1TrueDBGrid2.Columns.Count - 1

    C1MultiSelect1.Items.Add(C1TrueDBGrid2.Columns(i).Caption)

    Next

    Thanks,

    Victor

  • Posted 26 February 2020, 4:22 am EST

    Hi,

    Your case has been replied on the given link:

    https://www.grapecity.com/forums/winforms-edition/help-with-comparing-two-c1#hi-victoras-we-are-filteri

    Regards,

    Prabhat Sharma.

  • Posted 26 February 2020, 12:07 pm EST

    Hi Prabhat,

    This is not the same case. I am trying to load the C1MultiSelect control with only column names identical in both Grids.

    For example:

    if Grid1 contains columns FIF, NSN, AGD

    and Grid2 contains FIF, NSN, AGD, SCOUNYRY, Title, Location

    I only want to load the control with FIF, NSN, AGD.

    Thanks,

    Victor

  • Posted 27 February 2020, 3:01 am EST

    Hi Victor,

    Here the code snippet is given below to achieve the desired behavior :

    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
      For j As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
        If C1TrueDBGrid1.Splits(0).DisplayColumns(i).Name = C1TrueDBGrid2.Splits(0).DisplayColumns(j).Name Then
           C1MultiSelect1.Items.Add(C1TrueDBGrid1.Splits(0).DisplayColumns(i).Name)
           Exit For
        End If
      Next
    Next
    

    You can also take a look into the attached sample implementing the same.

    Regards,

    Prabhat Sharma.

    TrueDBGridColumnCaptionDemo.zip

  • Posted 2 March 2020, 11:49 am EST

    It works.

    Thank you.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels