Help with replacing Combobox control with C1MultiSelect Control

Posted by: Victor.m.charles.civ on 4 March 2020, 3:17 am EST

  • Posted 4 March 2020, 3:17 am EST

    Hello,

    I'm currently searching a table by selecting records from a C1TrueDBGrid1 after passing filed name selected form a Combobox using its index value (iii), How do I modify the code to replace the combobox with a multiselect control to pass multiple fields instead of only one field from the combobox? For example if I select a row in C1TrueDBGrid1, I would like to search for the values in selected fields (e.g. NSN, Country) using the "AND' or "OR" approach. If "AND" values in selected fields must match and if "OR" either values must match the values in AOP5A.xml. The results are then displayed in C1TrueDBGrid5.


    Enclosed is a sample project using the Combobox control.

    Thanks,

    Victor
  • Replied 4 March 2020, 3:29 am EST

    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.

    As per our understanding, you want to show only those selected records of Grid1 on the grid5 whose selected columns values (By Multiselect) matched with grid2. If this understanding is correct then please let us know.

    Regards,
    Prabhat Sharma.
  • Replied 5 March 2020, 7:35 am EST

    Hello Prabhat,

    Enclosed is a simplified version of the application. As mentioned I would like to replace the Combobox with the multiselect control to achieve the following using a Hidden Grid control (C1TrueDBGrid6)

    Part A:
    1. Select multiple columns from the Multislect control
    2. Select multiple rows/records from C1TrueDBGrid
    3. Cross check data in selected records for selected fields and cross
    check data in same fields from Grid6.

    4. We now have two options when matching rows in both Grids:

    1. Display matching data in one or more selected fields
    2. Display matching data in all selected fields

    Thanks,

    Victor
  • Replied 5 March 2020, 7:36 am EST

    WindowsApp1.zip
  • Replied 5 March 2020, 8:20 pm EST

    Hi Victor,

    You can put the code snippet given below on a button click to achieve your desired result:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim xyz As String = ""
    If C1TrueDBGrid1.SelectedRows.Count > 0 Then
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    For Each Srow In C1TrueDBGrid1.SelectedRows
    Console.WriteLine(C1TrueDBGrid1.SelectedRows.Count)
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(Srow) + "' OR "
    Next
    ' Uncomment the code to Display matching data in all selected fields
    'xyz = xyz.Remove(xyz.Length - 4, 4)
    'xyz = xyz + "AND "
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    End If
    fsLinkCHPT = New System.IO.FileStream(Application.StartupPath + "\AOP5A.xml", IO.FileMode.Open)
    dtsetLinkCHPT.Clear()
    dtsetLinkCHPT.ReadXml(fsLinkCHPT)
    fsLinkCHPT.Close()
    Dim FilteredDTA As DataTable
    FilteredDTA = dtsetLinkCHPT.Tables(0)
    Dim view5 As DataView
    view5 = New DataView(FilteredDTA)
    view5.RowFilter = xyz
    C1TrueDBGrid5.DataSource = view5
    C1TrueDBGrid1.SelectedRows.Clear()
    End Sub


    We have updated the sample with the same code, please have a look.

    Regards,
    Prabhat Sharma.
    WindowsApp1_Modifed.zip
  • Replied 6 March 2020, 1:28 am EST

    Hello Prabhat,

    I need to cross check the data for column selected in Grid1 against the hidden Grid (Grid6).

    Please look at the enclosed slide, when selecting PRT in Grid1, there should be no results since PRT is not included in the COUNTRY column of Grid6.

    Thanks,

    Victor

    Screenshot.zip
  • Replied 6 March 2020, 1:45 am EST

    Hello Prabhat,

    When there is a match, I would like to display the matching records from both Grid1 and Grid6 in Grid5.

    Thanks,

    Victor
  • Replied 7 March 2020, 3:29 am EST

    Hello Prabhat,

    I noticed the code below you sent me does not include C1TrueDBGRid6, which I think would be needed to be compared with C1TrueDBGrid1.

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim xyz As String = ""
    If C1TrueDBGrid1.SelectedRows.Count > 0 Then
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    For Each Srow In C1TrueDBGrid1.SelectedRows
    Console.WriteLine(C1TrueDBGrid1.SelectedRows.Count)
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(Srow) + "' OR "
    Next
    ' Uncomment the code to Display matching data in all selected fields
    'xyz = xyz.Remove(xyz.Length - 4, 4)
    'xyz = xyz + "AND "
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    End If
    fsLinkCHPT = New System.IO.FileStream(Application.StartupPath + "\AOP5A.xml", IO.FileMode.Open)
    dtsetLinkCHPT.Clear()
    dtsetLinkCHPT.ReadXml(fsLinkCHPT)
    fsLinkCHPT.Close()
    Dim FilteredDTA As DataTable
    FilteredDTA = dtsetLinkCHPT.Tables(0)
    Dim view5 As DataView
    view5 = New DataView(FilteredDTA)
    view5.RowFilter = xyz
    C1TrueDBGrid5.DataSource = view5
    C1TrueDBGrid1.SelectedRows.Clear()
    End Sub

    My goal is for example.

    Select Country and AGD from the Multiselect control
    Select two records in Grid1 where
    Country AGD
    USA M55
    BEL M59
    System compares values selected in Grid6
    if Grid6 contains:
    Country AGD
    USA M55
    BEL M59

    Grid1 Displays:

    Country AGD
    USA M55
    BEL M59
    USA M55
    BEL M59

    Which will than be sorted for selected fields.

    Please note if using the "OR" approach

    Grid5 would display additional records where either values in COUNTRY and AGD is included in Grid6.


    Thanks,

    Victor
  • Replied 8 March 2020, 6:02 pm EST

    Hello,

    >>When there is a match, I would like to display the matching records from both Grid1 and Grid6 in Grid5.
    As per our understanding, you want to compare the selected record of Grid 1 with the Grid6 and we modified the sample as per this understanding.

    If this does not resolve your issue then please let us know.

    Regards,
    Prabhat Sharma.
    WindowsApp1_Modifed1.zip
  • Replied 13 March 2020, 4:49 am EST

    Hi Prabhat,

    Can you please modify your code below to include: Radionbutton1 is checked for "OR" and Radiobutton2 is checked for "AND".

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim xyz As String = ""
    If C1TrueDBGrid1.SelectedRows.Count > 0 Then
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    For Each Srow In C1TrueDBGrid1.SelectedRows
    Console.WriteLine(C1TrueDBGrid1.SelectedRows.Count)
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(Srow) + "' OR "
    Next
    ' Uncomment the code to Display matching data in all selected fields
    'xyz = xyz.Remove(xyz.Length - 4, 4)
    'xyz = xyz + "AND "
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    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

    Thanks,

    Victor
  • Replied 13 March 2020, 3:41 pm EST

    Hi Prabhat,

    I noticed in error in the logic when using the "AND" option. For example when I select COUNTRY and AGD4 Fields and select two records in Grid1. xyz = [COUNTRY] = 'ITA' OR [COUNTRY] = 'FRA' AND [AGD4] = 'SS109' OR [AGD4] = 'MLEF1A'

    However xyz should be as follows:

    xyz = [COUNTRY] = 'ITA' AND [AGD4] = 'SS109' OR [COUNTRY] = 'FRA' AND [AGD4] = 'MLEF1A'

    Can you please modify the code to obtain the desired format for xyz.

    Thanks,

    Victor
  • Replied 15 March 2020, 6:14 pm EST

    Hello Victor,

    Here is the modified code achieving your desired result, please have a look.

       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim xyz As String = ""
    If C1TrueDBGrid1.SelectedRows.Count > 0 Then
    If RadioButton1.Checked Then
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    For Each Srow In C1TrueDBGrid1.SelectedRows
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(Srow) + "' OR "
    Next
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    End If

    If RadioButton2.Checked Then
    For Each Srow In C1TrueDBGrid1.SelectedRows
    For iCol = 0 To C1MultiSelect1.SelectedItems.Count - 1
    xyz = xyz + "[" + C1MultiSelect1.SelectedItems(iCol).Value + "] = '" + C1TrueDBGrid1.Columns(C1MultiSelect1.SelectedItems(iCol).Value).CellText(Srow) + "' AND "
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    xyz = xyz + "OR "
    Next
    xyz = xyz.Remove(xyz.Length - 4, 4)
    Console.WriteLine(xyz)
    End If
    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 16 March 2020, 11:46 am EST

    It works!
    Thank you.
    Victor
  • Replied 18 March 2020, 10:07 am EST

    Hello Prabhat,

    How do I modify the code in Part B to sort the Grid (C1scree3) populated using the code in part A? I can't figure out how to modify the code without a datatable.

    Thanks,
    Victor

    Part A:
    If RadioButton15.Checked Then
    'Display Merging data from Grids1 & 2
    C1Screen3.Rows.Clear
    If RadioButton5.Checked Then
    Dim b As Boolean
    For i As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    b = False
    If C1Data.Columns(0).CellText(i) <> "" Then
    For j As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1Data.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1DataB.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1Data.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1Data.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next

    For i As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    b = False
    If C1DataB.Columns(0).CellText(i) <> "" Then
    For j As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1DataB.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1Data.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1DataB.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1DataB.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next
    End If
    If RadioButton6.Checked Then
    Dim b As Boolean
    For i As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1Data.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1DataB.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1Data.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1Data.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next

    For i As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1DataB.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1Data.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1DataB.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1DataB.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next
    End If
    If C1Screen3.Rows.Count = 0 Then
    MsgBox("No Matches Found")
    End If
    Part B:
    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 = dr.AsDataView()
    DataView.Sort = str
    C1Screen3.DataSource = DataView
    Exit Sub
    End If
  • Replied 18 March 2020, 7:34 pm EST

    Hello Victor,

    In spite of add rows to the TrueDBGrid you can add the rows in a DataTable object and assign this DataTable as the DataSoruce of grid5. The code snippet is given below:

       Dim TDB5DataTable As DataTable = New DataTable()
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    TDB5DataTable.Columns.Add(New DataColumn(C1TrueDBGrid1.Splits(0).DisplayColumns(i).Name, C1TrueDBGrid1.Splits(0).DisplayColumns(i).DataColumn.DataType))
    Next

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    ' C1TrueDBGrid5.Rows.Clear()
    TDB5DataTable.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid1.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid2.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid1.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1TrueDBGrid2.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1TrueDBGrid2.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.Rows.Add(dr)
    End If
    End If
    Next
    End If
    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 = TDB5DataTable.AsDataView()
    DataView.Sort = str
    C1TrueDBGrid5.DataSource = DataView
    End Sub


    You need to use TDB in bound mode as sorting is not possible in unbound mode in TDB.

    Hope this helps.

    Regards,
    Prabhat Sharma.
  • Replied 22 March 2020, 6:26 am EST

    Hello Prabhat,

    Where do I include the following code?

    Dim TDB5DataTable As DataTable = New DataTable()
    For i As Integer = 0 To C1TrueDBGrid1.Splits(0).DisplayColumns.Count - 1
    TDB5DataTable.Columns.Add(New DataColumn(C1TrueDBGrid1.Splits(0).DisplayColumns(i).Name, C1TrueDBGrid1.Splits(0).DisplayColumns(i).DataColumn.DataType))
    Next

    I am receiving the following error when attempting to include it in the same button click event.

    'TDB5DataTable' is not declared. It may be inaccessible due to its protection level.'


    Thanks,

    Victor
  • Replied 22 March 2020, 7:59 pm EST

    Hi Victor,

    This error is not specific to C1 controls and as per our understanding, you are using the object out of its protection level.
    You can share the stripped-down sample of your application replicating the issue so that we can assist you in a better way.

    Regards,
    Prabhat Sharma.
  • Replied 23 March 2020, 2:14 am EST

    Hello Prabhat,

    I'm not getting an error with the code below but TDB5DataTable record count is 0 when trying to sort. How do I modify the code to populate TDB5DataTable with data from C1Screen3.

    Thanks,

    Victor


    Code:

    If RadioButton15.Checked Then
    MsgBox("A")
    'Display Merging data from Grids1 & 2
    C1Screen3.Rows.Clear() '=========================================================================================
    If RadioButton5.Checked Then
    ' MsgBox("MMMM")
    Dim b As Boolean
    For i As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    b = False
    If C1Data.Columns(0).CellText(i) <> "" Then
    ' MsgBox("JJJJJJJJJJJJJJ")
    For j As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1Data.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1DataB.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1Data.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1Data.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next
    'MsgBox("JJJJ")
    For i As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    b = False
    If C1DataB.Columns(0).CellText(i) <> "" Then
    For j As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1DataB.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1Data.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1DataB.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1DataB.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next
    End If
    ' MsgBox("KKK")

    '===========================================================================
    If RadioButton6.Checked Then
    Dim b As Boolean
    For i As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1Data.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1DataB.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1Data.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1Data.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next

    For i As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1DataB.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1Data.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 = C1Screen3.NewRow()
    For col As Integer = 0 To C1DataB.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1DataB.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    C1Screen3.Rows.Add(dr)
    End If
    End If
    Next
    End If
    If C1Screen3.Rows.Count = 0 Then
    MsgBox("No Matches Found")
    End If
    '****************************
    MsgBox(C1Screen3.Rows.Count) - COUNT IS NOT 0
    Dim TDB5DataTable As DataTable = New DataTable()
    For i As Integer = 0 To C1Screen3.Splits(0).DisplayColumns.Count - 1
    TDB5DataTable.Columns.Add(New DataColumn(C1Screen3.Splits(0).DisplayColumns(i).Name, C1Screen3.Splits(0).DisplayColumns(i).DataColumn.DataType))
    Next
    MsgBox(TDB5DataTable.Rows.Count) ***** COUNT is 0
    Dim DataView As DataView = TDB5DataTable.AsDataView()
    DataView.Sort = " NSN ASC"
    C1Screen3.DataSource = DataView
    '*******************************
    Exit Sub
    End If
  • Replied 23 March 2020, 9:15 pm EST

    Hi Victor,

    The code snippet you provided has lots of unknowns so it was very tough to get the exact reason of the issue you are facing but as per you code snippet is given below, we can see that you are not adding any row in the TDB5DataTable DataTable that is why you are getting the row count as 0.

    Dim TDB5DataTable As DataTable = New DataTable()
    For i As Integer = 0 To C1Screen3.Splits(0).DisplayColumns.Count - 1
    TDB5DataTable.Columns.Add(New DataColumn(C1Screen3.Splits(0).DisplayColumns(i).Name, C1Screen3.Splits(0).DisplayColumns(i).DataColumn.DataType))
    Next
    MsgBox(TDB5DataTable.Rows.Count) ***** COUNT is 0
    Dim DataView As DataView = TDB5DataTable.AsDataView()
    DataView.Sort = " NSN ASC"
    C1Screen3.DataSource = DataView


    Please share a stripped-down sample with your requirement so that we can provide you a helpful solution as per your need.

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

    Hi Prabhat,

    I included the code in the Button2 click event in an old sample I sent you a few weeks ago. Once you upload the Grids with excel files in the TestExcel folder and press Button2, you'll notice the C1TrueDBGrid5 count is 0 when trying to sort by NSN.

    Thanks,WindowsAppTEST.zip
  • Marked as Answer

    Replied 24 March 2020, 4:58 pm EST

    Hello,

    As you are first using TDB5 in unbound mode then using it in bound mode to use sorting which is not possible and the correct approach.
    So I modified your sample as per your need, please have a look.

    Regards,
    Prabhat Sharma.
    WindowsAppTEST_Mod1.zip
  • Replied 25 March 2020, 2:55 am EST

    Hello Prabhat,

    I change the bottom part of the code to sort by selected columns in the MultiSelect control, but receiving same error message regarding Grid being bound. How do I modify it to avoid this error?

    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 = FilteredDTA1.AsDataView()
    DataView.Sort = str
    C1Screen3.DataSource = DataView

    Thanks,

    Victor
  • Replied 25 March 2020, 3:03 am EST

    Hello,

    Error is on line: C1Screen3.Rows.Clear()

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

    Names replaced from your code:
    C1TrueDBGrid1 - C1Data
    C1TrueDBGrid2 - C1DataB
    C1TrueDBGrid5 - C1Screen3

    Code:

    Dim xyz As String = ""
    Dim view5 As DataView
    ' Dim FilteredDTA As DataTable

    '********************************************************
    If RadioButton15.Checked Then
    'Display Merging data from Grids1 & 2

    Dim TDB5DataTable As DataTable = New DataTable()
    For i As Integer = 0 To C1Screen3.Splits(0).DisplayColumns.Count - 1
    TDB5DataTable.Columns.Add(New DataColumn(C1Screen3.Splits(0).DisplayColumns(i).Name, C1Screen3.Splits(0).DisplayColumns(i).DataColumn.DataType))
    Next
    If RadioButton5.Checked Then
    ' MsgBox("MMMM")
    Dim b As Boolean
    For i As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    b = False
    If C1Data.Columns(0).CellText(i) <> "" Then
    ' MsgBox("JJJJJJJJJJJJJJ")
    For j As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1Data.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1DataB.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1Data.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1Data.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.Rows.Add(dr)
    End If
    End If
    Next
    'MsgBox("JJJJ")
    For i As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    b = False
    If C1DataB.Columns(0).CellText(i) <> "" Then
    For j As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1DataB.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) = C1Data.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1DataB.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1DataB.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.Rows.Add(dr)
    End If
    End If
    Next
    End If
    ' MsgBox("KKK")

    '===========================================================================
    If RadioButton6.Checked Then
    Dim b As Boolean
    For i As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1Data.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1DataB.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1Data.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1Data.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.Rows.Add(dr)
    End If
    End If
    Next

    For i As Integer = 0 To C1DataB.Splits(0).Rows.Count - 1
    If C1DataB.Columns(0).CellText(i) <> "" Then
    b = False
    For j As Integer = 0 To C1Data.Splits(0).Rows.Count - 1
    If C1Data.Columns(0).CellText(j) <> "" Then
    For k As Integer = 0 To C1MultiSelect1.SelectedItems.Count - 1
    If C1DataB.Columns(C1MultiSelect1.SelectedItems(k).Value).CellText(i) <> C1Data.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 = TDB5DataTable.NewRow()
    For col As Integer = 0 To C1DataB.Splits(0).DisplayColumns.Count - 1
    dr(col) = C1DataB.Splits(0).DisplayColumns(col).DataColumn.CellText(i)
    Next
    TDB5DataTable.Rows.Add(dr)
    End If
    End If
    Next
    End If
    C1Screen3.DataSource = TDB5DataTable
    If C1Screen3.Splits(0).Rows.Count = 0 Then
    MsgBox("No Matches Found")
    End If
    '****************************
    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 = TDB5DataTable.AsDataView()
    DataView.Sort = str
    C1screen3.DataSource = DataView

    ' MsgBox(TDB5DataTable.Rows.Count) ' ***** COUNT Is 0
    ' Dim DataView As DataView = TDB5DataTable.AsDataView()
    ' DataView.Sort = " NSN ASC"
    ' C1Screen3.DataSource = DataView

    End If
  • Replied 25 March 2020, 3:33 am EST

    Please disregard, my last post, I will close this issue.
    Thanks,

    Victor
Need extra support?

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

Learn More

Forum Channels