MsFlexGrid / ListBox 
Author Message
 MsFlexGrid / ListBox

Hi:
Im trying to insure the data in the MSFlexGrid1 is in
List1 with the following procedeure; but, it is not
working. Any help would be appreciated.

Private Sub Command1_Click()

Dim irow, erow As Integer
  For irow = 1 To MSFlexGrid1.Rows - 1
   For erow = 0 To List1.ListCount - 1
If MSFlexGrid1.TextMatrix(irow, 1) <> List1.List(erow)Then
      MSFlexGrid1.TextMatrix(irow, 1) = List1.List(erow)
         Else: MSFlexGrid1.TextMatrix(irow, 1) = ""
            End If
       Next erow
       Next irow
End Sub

Thanks



Thu, 15 Sep 2005 13:52:43 GMT  
 MsFlexGrid / ListBox

Quote:
> Dim irow, erow As Integer

Note that the line above is declaring one Variant (irow) and one Integer (erow)... each
variable type must be declared separately. But anyway.....

Here's one way...
'==============
Option Explicit

Private Sub Command1_Click()
   Dim i As Integer
   Dim j As Integer
   Dim sCurrent As String
   Dim iMatches As Integer

   With MSFlexGrid1
      For i = .FixedRows To .Rows - 1
         iMatches = 0 'Clear the counter
         'Pass the textmatrix to a variable
         'to get a little more speed out of it plus
         'save some typing
         sCurrent = .TextMatrix(i, 1)
         For j = 0 To List1.ListCount - 1
            If sCurrent = List1.List(j) Then
               iMatches = iMatches + 1
            End If
         Next
         If iMatches = 0 Then
            .TextMatrix(i, 1) = "NA" 'you can use "" or whatever
         End If
      Next
   End With

End Sub

Private Sub Form_Load()
   Dim i As Integer
   'Put a few items in the listbox
   For i = 1 To 10
      List1.AddItem "Item " & i
   Next
   'Put a few items in the grid in random order
   With MSFlexGrid1
      .Rows = 20
      .Cols = 2
      .FixedCols = 0
      .FixedRows = 1
      For i = .FixedRows To .Rows - 1
         .TextMatrix(i, 1) = "Item " & Int(Rnd * 20)
      Next
   End With
End Sub
'==============

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com/ - Please keep it in the groups

Quote:

> Hi:
> Im trying to insure the data in the MSFlexGrid1 is in
> List1 with the following procedeure; but, it is not
> working. Any help would be appreciated.

> Private Sub Command1_Click()

> Dim irow, erow As Integer
>   For irow = 1 To MSFlexGrid1.Rows - 1
>    For erow = 0 To List1.ListCount - 1
> If MSFlexGrid1.TextMatrix(irow, 1) <> List1.List(erow)Then
>       MSFlexGrid1.TextMatrix(irow, 1) = List1.List(erow)
>          Else: MSFlexGrid1.TextMatrix(irow, 1) = ""
>             End If
>        Next erow
>        Next irow
> End Sub

> Thanks



Thu, 15 Sep 2005 14:18:49 GMT  
 MsFlexGrid / ListBox

Ken: Thank you very much for the excellent example.

Quote:
>-----Original Message-----

>> Dim irow, erow As Integer
>Note that the line above is declaring one Variant (irow)

and one Integer (erow)... each
Quote:
>variable type must be declared separately. But
anyway.....

>Here's one way...
>'==============
>Option Explicit

>Private Sub Command1_Click()
>   Dim i As Integer
>   Dim j As Integer
>   Dim sCurrent As String
>   Dim iMatches As Integer

>   With MSFlexGrid1
>      For i = .FixedRows To .Rows - 1
>         iMatches = 0 'Clear the counter
>         'Pass the textmatrix to a variable
>         'to get a little more speed out of it plus
>         'save some typing
>         sCurrent = .TextMatrix(i, 1)
>         For j = 0 To List1.ListCount - 1
>            If sCurrent = List1.List(j) Then
>               iMatches = iMatches + 1
>            End If
>         Next
>         If iMatches = 0 Then
>            .TextMatrix(i, 1) = "NA" 'you can use "" or
whatever
>         End If
>      Next
>   End With

>End Sub

>Private Sub Form_Load()
>   Dim i As Integer
>   'Put a few items in the listbox
>   For i = 1 To 10
>      List1.AddItem "Item " & i
>   Next
>   'Put a few items in the grid in random order
>   With MSFlexGrid1
>      .Rows = 20
>      .Cols = 2
>      .FixedCols = 0
>      .FixedRows = 1
>      For i = .FixedRows To .Rows - 1
>         .TextMatrix(i, 1) = "Item " & Int(Rnd * 20)
>      Next
>   End With
>End Sub
>'==============

>--
>Ken Halter - MS-MVP-VB - http://www.vbsight.com/ -

Please keep it in the groups
Quote:




- Show quoted text -

Quote:
>> Hi:
>> Im trying to insure the data in the MSFlexGrid1 is in
>> List1 with the following procedeure; but, it is not
>> working. Any help would be appreciated.

>> Private Sub Command1_Click()

>> Dim irow, erow As Integer
>>   For irow = 1 To MSFlexGrid1.Rows - 1
>>    For erow = 0 To List1.ListCount - 1
>> If MSFlexGrid1.TextMatrix(irow, 1) <> List1.List(erow)
Then
>>       MSFlexGrid1.TextMatrix(irow, 1) = List1.List
(erow)
>>          Else: MSFlexGrid1.TextMatrix(irow, 1) = ""
>>             End If
>>        Next erow
>>        Next irow
>> End Sub

>> Thanks

>.



Thu, 15 Sep 2005 23:58:26 GMT  
 MsFlexGrid / ListBox
This should be a little faster... uses a bool instead of a counter (it was late when I
posted that first sample <g>)
'==========
Private Sub Command1_Click()
   Dim i As Integer
   Dim j As Integer
   Dim sCurrent As String
   Dim bMatchFound As Boolean

   With MSFlexGrid1
      For i = .FixedRows To .Rows - 1
         bMatchFound = False
         sCurrent = .TextMatrix(i, 1)
         For j = 0 To List1.ListCount - 1
            If sCurrent = List1.List(j) Then
               bMatchFound = True
               Exit For
            End If
         Next
         If Not bMatchFound Then
            .TextMatrix(i, 1) = "NA" 'you can use "" or whatever
         End If
      Next
   End With

End Sub
'==========

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com/ - Please keep it in the groups

Quote:

> Ken: Thank you very much for the excellent example.



Fri, 16 Sep 2005 12:34:25 GMT  
 MsFlexGrid / ListBox
Ken:
I compared the two with a timer and as you stated the
latter is faster. Also, and probably more important, is
the fact I now see the proper way to set up an "If
statement"
Thanks again

Quote:
>-----Original Message-----
>This should be a little faster... uses a bool instead of

a counter (it was late when I
Quote:
>posted that first sample <g>)
>'==========
>Private Sub Command1_Click()
>   Dim i As Integer
>   Dim j As Integer
>   Dim sCurrent As String
>   Dim bMatchFound As Boolean

>   With MSFlexGrid1
>      For i = .FixedRows To .Rows - 1
>         bMatchFound = False
>         sCurrent = .TextMatrix(i, 1)
>         For j = 0 To List1.ListCount - 1
>            If sCurrent = List1.List(j) Then
>               bMatchFound = True
>               Exit For
>            End If
>         Next
>         If Not bMatchFound Then
>            .TextMatrix(i, 1) = "NA" 'you can use "" or
whatever
>         End If
>      Next
>   End With

>End Sub
>'==========

>--
>Ken Halter - MS-MVP-VB - http://www.vbsight.com/ -

Please keep it in the groups
Quote:




- Show quoted text -

Quote:

>> Ken: Thank you very much for the excellent example.

>.



Sat, 17 Sep 2005 00:48:34 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Extracting data from listbox into MSFlexGrid

2. can msflexgrid work like listbox

3. Giving msflexgrid a listbox look

4. Move ListBox items to another ListBox

5. Store Text in Listbox.Editing, and storing in Listbox

6. VB3: Setting listbox based on value of other listbox

7. Write contents of listbox to text file/populate listbox from text file

8. How to scroll a listbox and scroll another listbox along

9. HELP: ListBox scrolling Q (listbox)

10. NEW to VB -- Limit ListBox, Print ListBox

11. Want to hide listbox when user click anywhere other than the listbox

12. populating vb.net listbox from selected items of another listbox

 

 
Powered by phpBB® Forum Software