Help with missing column error when cross checking data from two Grids

Posted by: Victor.m.charles.civ on 4 March 2020, 9:31 am EST

  • Posted 4 March 2020, 9:31 am EST

    Hi,

    When attempting to cross checking data in two Grids I receive the following error message:
    System.IndexOutOfRangeException: 'Cannot find column 6.'

    On line:
    For row As Integer = 0 To C1TrueDBGrid6.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid6.Splits(0).DisplayColumns(row).DataColumn.CellText(i)
    Next

    Grid1 contains 5 columns and Grid6 contains 6 columns, How of I modify the code to work regardless of the number of columns in both Grids?

    Enclosed is the sample project.

    Thanks,

    Victor

    GRIDTESTING022520.zip
  • Replied 4 March 2020, 7:45 pm EST

    Hi Victor,

    The sample you attached is very complex to understand what you want to achieve. You are requested to provide a sample that has only those controls on the forms by which and on which you want to perform the operation and also remove the extra code that is not required.

    Regards,
    Prabhat Sharma.
  • Replied 5 March 2020, 9:01 am EST

    Hello Prabhat,

    Enclosed is the modified sample project.

    Kind regards,

    Victor

    GRIDTESTING022520.zip
  • Replied 5 March 2020, 9:50 am EST

    Hello Prabhat,

    I have a similar error to my initial case but this time both Grids 1 & 2 have the same number columns. Do you know what is causing this error.

    Error location:

    For row As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid1.Splits(0).DisplayColumns(row).DataColumn.CellText(i)
    Next

    Error message:
    System.IndexOutOfRangeException: 'Cannot find column 0.'


    Code:
    If RadioButton4.Checked Then
    'Set the all rows to visible initially
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    ' C1TrueDBGrid1.Splits(0).Rows(i).Visible = True
    Next

    C1TrueDBGrid3.Rows.Clear()
    Dim b As Boolean() = New Boolean(C1MultiSelect1.SelectedItems.Count - 1) {}

    C1TrueDBGrid4.Rows.Clear()
    Dim c As Boolean() = New Boolean(C1MultiSelect1.SelectedItems.Count - 1) {}

    'If any column is selected by C1MultiSelect
    If C1MultiSelect1.SelectedItems.Count > 0 Then
    'Iterate for all rows of main TDB
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    'Iterate for each column selected by C1MultiSelect
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    b(k) = False
    If C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(k).Value.ToString).CellText(i) = C1TrueDBGrid2.Columns(C1MultiSelect1.SelectedItems(k).Value.ToString).CellText(i).ToString Then
    b(k) = True
    End If
    Next
    'And Filter
    If RadioButton2.Checked Then
    'And Filter
    Dim temp = False
    For l As Integer = 0 To b.Count - 1
    If b(l) = False Then
    temp = True
    Exit For
    End If
    Next
    If Not temp Then
    ' C1TrueDBGrid1.Splits(0).Rows(i).Visible = False
    Dim dr As DataRow = Me.C1TrueDBGrid3.NewRow
    For row As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid1.Splits(0).DisplayColumns(row).DataColumn.CellText(i)
    Next
    C1TrueDBGrid3.Rows.Add(dr)
    End If

    If Not temp Then
    ' C1TrueDBGrid1.Splits(0).Rows(i).Visible = False
    Dim dr As DataRow = Me.C1TrueDBGrid4.NewRow
    For row As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid1.Splits(0).DisplayColumns(row).DataColumn.CellText(i)
    Next
    C1TrueDBGrid4.Rows.Add(dr)
    End If
    End If
    'Or Filter
    If RadioButton1.Checked Then
    Dim temp = True
    For l As Integer = 0 To b.Count - 1
    If b(l) = True Then
    temp = False
    Exit For
    End If
    Next
    ' MsgBox("mmmmmmmm")
    If Not temp Then
    ' MsgBox("nnn")

    Dim dr As DataRow = Me.C1TrueDBGrid3.NewRow

    For row As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid1.Splits(0).DisplayColumns(row).DataColumn.CellText(i)
    Next
    C1TrueDBGrid3.Rows.Add(dr)
    ' C1TrueDBGrid1.Splits(0).Rows(i).Visible = False
    End If
    End If
    Next

    End If

    ' Display data og GRID2

    'Set the all rows to visible initially
    For i As Integer = 0 To C1TrueDBGrid2.Splits(0).Rows.Count - 1
    ' C1TrueDBgrid2.Splits(0).Rows(i).Visible = True
    Next

    C1TrueDBGrid4.Rows.Clear()
    'If any column is selected by C1MultiSelect
    If C1MultiSelect1.SelectedItems.Count > 0 Then
    'Iterate for all rows of main TDB
    For i As Integer = 0 To C1TrueDBGrid2.Splits(0).Rows.Count - 1
    'Iterate for each column selected by C1MultiSelect
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    b(k) = False
    If C1TrueDBGrid2.Columns(C1MultiSelect1.SelectedItems(k).Value.ToString).CellText(i) = C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(k).Value.ToString).CellText(i).ToString Then
    b(k) = True
    End If
    Next
    'And Filter
    If RadioButton2.Checked Then
    'And Filter
    Dim temp = False
    For l As Integer = 0 To b.Count - 1
    If b(l) = False Then
    temp = True
    Exit For
    End If
    Next
    If Not temp Then
    ' C1TrueDBgrid2.Splits(0).Rows(i).Visible = False
    Dim dr As DataRow = Me.C1TrueDBGrid4.NewRow
    For row As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid2.Splits(0).DisplayColumns(row).DataColumn.CellText(i)
    Next
    C1TrueDBGrid4.Rows.Add(dr)
    End If
    End If
    'Or Filter
    If RadioButton1.Checked Then
    Dim temp = True
    For l As Integer = 0 To b.Count - 1
    If b(l) = True Then
    temp = False
    Exit For
    End If
    Next
    ' MsgBox("mmmmmmmm")
    If Not temp Then
    ' MsgBox("nnn")

    Dim dr As DataRow = Me.C1TrueDBGrid4.NewRow

    For row As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid2.Splits(0).DisplayColumns(row).DataColumn.CellText(i)
    Next
    C1TrueDBGrid4.Rows.Add(dr)
    ' C1TrueDBgrid2.Splits(0).Rows(i).Visible = False
    End If
    End If
    Next
    End If

    '******************************************************************************************
    Dim dt As DataTable = New DataTable()
    Dim dc As DataColumn
    For i As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
    dc = New DataColumn
    dc.ColumnName = C1TrueDBGrid2.Splits(0).DisplayColumns(i).Name
    dc.Caption = dc.ColumnName
    dc.DataType = C1TrueDBGrid2.Splits(0).DisplayColumns(0).DataColumn.DataType
    dt.Columns.Add(dc)
    Next
    For i As Integer = 0 To C1TrueDBGrid3.Splits(0).Rows.Count - 1
    Dim dr As DataRow = dt.NewRow
    For col As Integer = 0 To C1TrueDBGrid3.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid3.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    dt.Rows.Add(dr)
    Next

    For i As Integer = 0 To C1TrueDBGrid4.Splits(0).Rows.Count - 1
    Dim demoDb As C1TrueDBGrid = New C1TrueDBGrid()
    Dim dr As DataRow = dt.NewRow
    Dim temp As Boolean = False
    For col As Integer = 0 To C1TrueDBGrid4.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid4.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    For j As Integer = 0 To C1TrueDBGrid3.Splits(0).Rows.Count - 1
    For col As Integer = 0 To C1TrueDBGrid3.Splits(0).DisplayColumns.Count - 1
    If dr(col) <> C1TrueDBGrid3.Splits(0).DisplayColumns(col).DataColumn.CellText(i) Then
    temp = True
    Exit For
    End If
    Next
    If temp Then
    dt.Rows.Add(dr)
    temp = False
    Exit For
    End If
    Next
    Next
    C1TrueDBGrid5.DataSource = dt

    ' Dim DataView As DataView = dt.AsDataView()
    ' DataView.Sort = " NSN ASC,SCOUNTRY ASC,COUNTRY ASC"
    'C1TrueDBGrid5.DataSource = DataView

    Dim str As String = C1MultiSelect1.SelectedItems(0).Value.ToString + " ASC"
    For item As Integer = 1 To C1MultiSelect1.SelectedItems.Count - 1
    str = str + "," + C1MultiSelect1.SelectedItems(item).Value.ToString + " ASC"
    Next
    Dim DataView As DataView = dt.AsDataView()
    DataView.Sort = str
    C1TrueDBGrid5.DataSource = DataView
    End If
    End Sub

    Thanks,

    Victor

  • Replied 5 March 2020, 8:41 pm EST

    Hi Victor,

    TDB6 has seven columns and TDB4 has 6 columns that are when assigning value to new DataRow of TDB for it was throwing error for that extra column value of TDB6.

    I have modified the sample as per the above-given comments, please have a look.

    Regards,
    Prabhat Sharma.
    GRIDTESTING022520_Modifed.zip
  • Replied 6 March 2020, 3:09 am EST

    Hello Prabhat,

    I'm only using your code from the button1 control in the sample I sent you (encloded) because for some reason I can not open projects you send me, Incase you have other codes elsewhere that impacts the projects.

    I'm still receiving the following error:
    System.IndexOutOfRangeException: 'Cannot find column 6.'

    In section:
    'And Filter
    If RadioButton2.Checked Then
    'And Filter
    Dim temp = False
    For l As Integer = 0 To bb.Count - 1
    If bb(l) = False Then
    temp = True
    Exit For
    End If
    Next
    If Not temp Then
    Dim dr As DataRow = Me.C1TrueDBGrid4.NewRow
    For row As Integer = 0 To C1TrueDBGrid6.Splits(0).DisplayColumns.Count - 1
    dr(row) = C1TrueDBGrid6.Splits(0).DisplayColumns(row).DataColumn.CellText(i) ************Error
    Next
    C1TrueDBGrid4.Rows.Add(dr)
    End If
    End If

    When I select SN and COUNTRY using the "AND" option. How do I fix this error?

    GRIDTESTING022520.zip
  • Replied 7 March 2020, 8:52 am EST

    Hello Prabhat,

    I think it will not be possible to show results from Grid1 and Grid6 in Grid5 as long as they don't have the same number of columns. Is it possible to compare columns in Grid1 and Grid5 and reload both Grids identical columns and display the results with only matching columns in Grid5?

    Thanks,,
    Victor
  • Replied 8 March 2020, 7:03 pm EST

    Hello Victor,

    >>Is it possible to compare columns in Grid1 and Grid6 and reload both Grids identical columns and display the results with only matching columns in Grid5?

    I have attached a sample as per the above-given comments, please have a look.

    Regards,
    Prabhat Sharma.
    WindowsApp1_ModifiedDemo.zip
  • Replied 9 March 2020, 7:52 am EST

    Hello Prabhat,

    We're half way there. Is it still possible to also include matching records from Grid1 in Grid6 even though they don't have the same number columns. The solution to include matching records with Grid1 from Grid6 in Grid5 is working.

    Thanks,

    Victor
  • Replied 9 March 2020, 9:29 am EST

    Hello Prabhat,

    I noticed a bug when selecting multiple fields. For example when I select AGD4 and COUNTRY and option where all fields data must the same in selected fields, Grid5 still displays record with COUNTRY = DEUX even when it's not available in Grid1.

    Thanks,

    Victor


    WindowsApp1.zip
  • Replied 10 March 2020, 12:29 am EST

    Hello Probhat,

    Enclosed is another snapshot showing the bug when selecting either field option. You'll notice records for 10412 appears even though not available in Grid1.

    This feature was working well before using Grid6 with extra columns.

    Kind regards,

    Victor Screenshot_031020.zip
  • Replied 10 March 2020, 10:38 pm EST

    Hi Victor,

    The data showing in your attached sample is different from the data shown in the attached screenshot.
    We have again modified the sample as per your need by implementing the AND and OR filtering logic which shows data similar in Grid1 and Grid6 in Grid5, please have a look.

    Regards,
    Prabhat Sharma.
    WindowsApp1_ModifiedNew.zip
  • Replied 11 March 2020, 1:08 am EST

    Hello Probhat,

    Looking at your code below. How are you comparing the values between Grid1 and Grid6?

    OR Logic"
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(i) + "' OR "
    Next
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    #End Region
    #Region "AND Logic"
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(i) + "' AND "
    Next
    ' Uncomment the code to Display matching data in all selected fields
    xyz = xyz.Remove(xyz.Length - 4, 4)
    xyz = xyz + "OR "
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)

    Thanks,

    Victor
  • Replied 11 March 2020, 8:18 am EST

    Hello Prabhat,

    I'm receiving the following error under the "AND" region when I select country:

    view5.RowFilter = xyz
    C1TrueDBGrid5.DataSource = view5 *****Error
    C1TrueDBGrid1.SelectedRows.Clear()


    Error: System.Data.SyntaxErrorException: 'Syntax error: Missing operand after '[COUNTRY]' operator.'

    Do you know why I'm receiving this error? Icopied the same code from you sample project to my project and using same XML files.

    Thanks,

    Victor
  • Replied 11 March 2020, 2:40 pm EST

    Hi Victor,

    As you can see in the attached GIF we could not face any issue in running the last attached sample. Please make sure you are commenting/uncommenting the correct region code for implementing AND/OR logic.

    For you ease we have put the AND/OR logic code on the selection of radio button at run time. Please modify the code on button1 click as given below:

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim xyz As String = ""
    If C1TrueDBGrid1.Splits(0).Rows.Count > 0 Then
    #Region "OR Logic"
    If RadioButton1.Checked Then
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(i) + "' OR "
    Next
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    End If
    #End Region
    #Region "AND Logic"
    If RadioButton2.Checked Then
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(i) + "' AND "
    Next
    ' Uncomment the code to Display matching data in all selected fields
    xyz = xyz.Remove(xyz.Length - 4, 4)
    xyz = xyz + "OR "
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    End If

    #End Region
    End If
    Dim FilteredDTA As DataTable
    FilteredDTA = C1TrueDBGrid6.DataSource
    Dim view5 As DataView
    view5 = New DataView(FilteredDTA)
    view5.RowFilter = xyz
    C1TrueDBGrid5.DataSource = view5
    C1TrueDBGrid1.SelectedRows.Clear()
    End Sub


    Regards,
    Prabhat Sharma.
  • Replied 11 March 2020, 11:51 pm EST

    Hello Probhat,

    It's working perfectly!

    Can you use the same approach for the other case where I'm selecting record(s) from grid1 and searching for data in selected columns from the Multiselect control?

    Thank You!

    Victor
  • Replied 11 March 2020, 11:51 pm EST

    Hello Probhat,

    It's working perfectly!

    Can you use the same approach for the other case where I'm selecting record(s) from grid1 and searching for data in selected columns from the Multiselect control?

    Thank You!

    Victor
  • Replied 11 March 2020, 11:51 pm EST

    It works!

    Thank You.

    Victor
  • Replied 12 March 2020, 4:17 am EST

    Hello Probhat,

    There seems to be al limitation based on the file size. I'm receiving the following error:

    System.StackOverflowException: 'Exception of type 'System.StackOverflowException' was thrown.'

    On Line: view5.RowFilter = xyz

    Is there a way not to duplicate search for same values when going through all the rows? Perhaps it me help avoid this error message.

    Thanks,

    Victor
  • Replied 12 March 2020, 4:19 am EST

    Hello again,

    If there is a limitation on columns or records size, is it on Grid1 or Grid6?

    Thanks,

    Victor
  • Replied 12 March 2020, 5:07 am EST

    Hello Prabhot,

    The size limitation seems to be on Grid1 because it works when I use a smaller file with Grid1.

    Victor
  • Replied 12 March 2020, 9:50 pm EST

    Hello Victor,

    >>Can you use the same approach for the other case where I'm selecting record(s) from grid1 and searching for data in selected columns from the Multiselect control?
    Yes, you can use the same approach for AND/OR filtering where you are selecting record(s) from grid1 and searching for data in selected columns from the Multiselect control.

    >>The size limitation seems to be on Grid1 because it works when I use a smaller file with Grid1.
    Can you please share a stripped-down sample with the data file with which you are getting the error? It will help us to replicate the issue and assist you accordingly.

    Regards,
    Prabhat Sharma.
  • Replied 13 March 2020, 12:49 am EST

    Hi Prabhat,

    It's a bit confusing with keeping up with multiple cases. To summarize below are my 4 goals. I may have confused you by sending too many messages. I will review old samples and better organize the solution for each goal, may send you a sample application if running into any issues with any of the 4 capabilities.

    Part A - Both Grid1 and Grid2 have same columns.

    1. Selecting Column(s) - Display matching results from Grid1 and Grid2 in Grid3 (Both Grid1 & Grid2 data)
    2. Selecting Column(s) and records from Grid1 - Display matching results from Grid1 and Grid2 in Grid3 (Both Grid1 & Grid2 data)

    Part B - Grid1 and Grid2 do not have the same columns.

    3. Selecting Column(s) - Display matching results from Grid1 and Grid2 in Grid3 (Grid2 data only)
    4. Selecting Column(s) and records from Grid1 - Display matching results from Grid1 and Grid2 in Grid3 (Grid2 data only)

    Thanks,

    Victor
  • Replied 15 March 2020, 5:39 am EST

    Hello Prabhat,

    I noticed a problem when I upload the data in Grids 1 & 2 from two excel files(countryAA.xls, CountryBB.xls), I'm trying to merge matching records in Grid5,

    Error Line: dr(row) = C1TrueDBGrid1.Splits(0).DisplayColumns(row).DataColumn.CellText(i)

    Error message: System.IndexOutOfRangeException: 'Cannot find column 0.'

    How do I fix this error?

    Thanks,

    Victor
    TestExcel.zip
  • Replied 15 March 2020, 8:03 pm EST

    Hello Victor,

    You can follow the same approach to achieve the desired result as implemented in the sample given on the following link:
    https://www.grapecity.com/forums/winforms-edition/help-with-comparing-two-c1#hi-victoras-we-are-filteri

    If this does not help then please share a stripped-down sample of your application by removing the extra code that has been done in the button7 Click event handler.

    Regards,
    Prabhat Sharma.
  • Replied 16 March 2020, 11:54 am EST

    Hello Prabhat,

    The sample is to show you the error when I load the files on the Grids. The code works if I load the Grids using the xml files. Are you able to run the application to replicate the error? The other codes are needed to upload the files, not much more I con remove from the version I sent you.

    Also the link you sent me does not take me to a specific thread, hard to locate which sample project you are referring to.

    Thanks,

    Victor
  • Replied 16 March 2020, 5:21 pm EST

    Hi Victor,

    I have modified your last attached sample as per your need, please have a look.

    Regards,
    Prabhat Sharma.
    TestExcel.zip
  • Replied 17 March 2020, 2:54 am EST

    Hello Prabhat,

    Thank you for the sample project but I'm looking to merge the matching records from Grids 1 & 2 in Grid5. The sample you sent me only shows search results in Grid5 with only Grid1 results.

    Can you please modify the code to show results from both Grids in Grid5.

    Thanks,

    Victor
  • Replied 17 March 2020, 7:44 pm EST

    Hi Victor,

    Please use the code snippet given below on a button7 click event handler to get your desired output (Matching data from grid1 and grid2 based on an applied filter.)

      Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    C1TrueDBGrid5.Rows.Clear() '=========================================================================================
    If RadioButton1.Checked Then
    Dim b As Boolean
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    b = False
    If C1TrueDBGrid1.Columns(0).CellText(i) <> "" Then
    For j As Integer = 0 To C1TrueDBGrid2.Splits(0).Rows.Count - 1
    If C1TrueDBGrid2.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1TrueDBGrid2.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(j) Then
    b = True
    Exit For
    End If
    Next
    If b Then
    Exit For
    End If
    End If
    Next
    If b Then
    Dim dr = C1TrueDBGrid5.NewRow()
    For col As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid1.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1TrueDBGrid5.Rows.Add(dr)
    End If
    End If
    Next

    For i As Integer = 0 To C1TrueDBGrid2.Splits(0).Rows.Count - 1
    b = False
    If C1TrueDBGrid2.Columns(0).CellText(i) <> "" Then
    For j As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    If C1TrueDBGrid1.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1TrueDBGrid2.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(j) Then
    b = True
    Exit For
    End If
    Next
    If b Then
    Exit For
    End If
    End If
    Next
    If b Then
    Dim dr = C1TrueDBGrid5.NewRow()
    For col As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid2.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1TrueDBGrid5.Rows.Add(dr)
    End If
    End If
    Next
    End If '===========================================================================
    If RadioButton2.Checked Then
    Dim b As Boolean
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    If C1TrueDBGrid1.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1TrueDBGrid2.Splits(0).Rows.Count - 1
    If C1TrueDBGrid2.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1TrueDBGrid2.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(j) Then
    b = True
    Exit For
    Else
    b = False
    End If
    Next
    If Not b Then
    Exit For
    End If
    End If
    Next
    If Not b Then
    Dim dr = C1TrueDBGrid5.NewRow()
    For col As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid1.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1TrueDBGrid5.Rows.Add(dr)
    End If
    End If
    Next

    For i As Integer = 0 To C1TrueDBGrid2.Splits(0).Rows.Count - 1
    If C1TrueDBGrid2.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1TrueDBGrid1.Splits(0).Rows.Count - 1
    If C1TrueDBGrid1.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1TrueDBGrid2.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(j) Then
    b = True
    Exit For
    Else
    b = False
    End If
    Next
    If Not b Then
    Exit For
    End If
    End If
    Next
    If Not b Then
    Dim dr = C1TrueDBGrid5.NewRow()
    For col As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid2.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1TrueDBGrid5.Rows.Add(dr)
    End If
    End If
    Next
    End If
    End Sub


    Regards,
    Prabhat Sharma.
  • Replied 18 March 2020, 12:15 am EST

    Hello Prabhat,

    It worked! Thank You.

    How do I modify the code below to merge results from both C1Data and C1DataB in C1Screen3?

    If RadioButton16.Checked Then
    Dim xyz As String = ""
    If C1Data.SelectedRows.Count > 0 Then
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    For Each Srow In C1Data.SelectedRows
    Console.WriteLine(C1Data.SelectedRows.Count)
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1Data.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(Srow) + "' OR "
    Next
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    End If
    Dim FilteredDTA As DataTable
    FilteredDTA = C1DataB.DataSource
    Dim view5 As DataView
    view5 = New DataView(FilteredDTA)
    view5.RowFilter = xyz
    C1Screen3.DataSource = view5
    Exit Sub
    End If

    Thanks,
    Victor
  • Replied 18 March 2020, 12:59 am EST

    Hello Prabhat,

    I'm receiving the following error when going between multiple option:

    System.InvalidOperationException: 'Not supported when the grid is bound'

    On line: C1Screen3.Rows.Clear()

    How do I avoid this error?

    Thanks,

    Victor
  • Marked as Answer

    Replied 18 March 2020, 2:42 am EST

    Hi Victor,

    The code snippet you provided has number of unknowns so it is not possible to get what you are doing exactly. SO please share a stripped-down sample showing your issue and your expected output.

    >>System.InvalidOperationException: 'Not supported when the grid is bound'
    C1TrueDBGrid.Rows.Clear() method works only in unbound mode if your using the grid in bound mode then it will throw the error. You need not to clear the rows if you are using grid in bound mode because using datasource property will clear data from the grid and then reassingn new data to the grid.

    Note : If the initial requirement of this thread is achieved then you are requested to close this thread and create a new case for your other issues.

    Regards,
    Prabhat
  • Replied 18 March 2020, 5:46 am EST

    Thank You.
Need extra support?

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

Learn More

Forum Channels