Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I use the below  code to auto scroll listbox items and work well.


I want to be able to scroll all the cells in column no 2 of the gridview order wise but I am not able to do it. I am using the listed  code with the help of timer control.


What I have tried:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       If multinumbers.ListBox6.SelectedIndex < multinumbers.ListBox6.Items.Count - 1 Then
           multinumbers.ListBox6.SelectedIndex += 1   'Highlight the next one in the list

           SendSMS()                     'Send a message to the new number

       Else
           Timer1.Stop()
           multinumbers.Label101.Text = "Your Message has Completed"     'Let the user know we're done
           MsgBox("Your Desired List has Completed.Now you can Create New List of New Numbers or Send again Message to previous Numbers !")
           multinumbers.Button7.Enabled = False
           multinumbers.Button12.Enabled = True
           multinumbers.Button2.Enabled = False
       End If
   End Sub



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'i want to check first row and cell value in datagridview

        DataGridView1.CurrentRow.Cells(1).Selected = True

        'Highlight the next one in the gridview row and check cell value

        If DataGridView1.CurrentRow.Index < DataGridView1.Rows.Count - 1 Then
            DataGridView1.CurrentRow.Cells(0).Selected += 1

            Dim myRegExp As RegExp
            Dim myMatches As MatchCollection
            Dim myMatch As Match

            myRegExp = New RegExp
            myRegExp.IgnoreCase = True
            myRegExp.Global = True

            myRegExp.Pattern = "(http|https|ftp|html)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*/*.html+"

            myMatches = myRegExp.Execute((DataGridView1.CurrentRow.Cells(1).Value.ToString))

            For Each myMatch In myMatches
                ListBox1.Items.Add(myMatch.Value)
            Next
        End If

    End Sub


More code but faild..............

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       Dim strSearchString As String
       Dim myRegExp As RegExp
       Dim myMatches As MatchCollection
       Dim myMatch As Match

       myRegExp = New RegExp
       myRegExp.IgnoreCase = True
       myRegExp.Global = True
       For Each myRow As DataGridViewRow In DataGridView1.Rows
           For Each myCell As DataGridViewCell In myRow.Cells
               If myRow.Index < DataGridView1.Rows.Count Then
                   DataGridView1.FirstDisplayedScrollingRowIndex = myRow.Index
                   strSearchString = myCell.Value.ToString

                   myRegExp.Pattern = "(http|https|ftp|html)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*/*.html+"
                   myMatches = myRegExp.Execute((strSearchString))

                   If InStr(myCell.Value.ToString, strSearchString, CompareMethod.Text) Then
                       myRow.Selected = True
                       For Each myMatch In myMatches
                           ListBox1.Items.Add(myMatch.Value)
                       Next

                   End If
               End If
           Next



       Next


   End Sub
Posted
Updated 11-Sep-22 4:45am
v5
Comments
RickZeeland 11-Sep-22 4:03am    
Can you show the declaration of the Timer? several timers are available in .NET.
Maciej Los 11-Sep-22 5:45am    
Wich Timer_Tick event are you using?

1 solution

If you would like to get or set selected cell, see this: Get and Set the Current Cell in DataGridView Control - Windows Forms .NET Framework | Microsoft Docs[^]

In other words, to select:
//first row
dataGridview1.Rows[0].Selected = true;
//10th row
dataGridview1.Rows[9].Selected = true;
//cell in column 1, Row 0.
dataGridView1.CurrentCell = dataGridView1[1,0];
 
Share this answer
 
Comments
noormian 11-Sep-22 23:05pm    
Yes i agree with you and i can get one cell value. But i want to get whole cells data from a specific column such as column no 2 from a datagridview and put into a listbox through timer.
Maciej Los 12-Sep-22 10:47am    
Take a deeep look at this line:
//cell in column 1, Row 0.
dataGridView1.CurrentCell = dataGridView1.Cells[1,0];
saify mian 14-Sep-22 6:20am    
Anyway, Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900