How to return all/multiple the Cell Addresses/Reference in Datagridview?

This is my new post but in continuation of Thread 78734244 of this forum.

I was wondering How Could i get all the Cell Addresses/Reference in Datagridview. The above thread was for
any single input of Cell Value to get its respective Cell Address in Datagridview.

Now I would like to have all Cell Addresses/References of DataGridView

ie for the below grid
6 9 7
8 1 5
2 4 3

and get list like below
6 is in cell (0,0)
9 is in cell (0,1)
7 is in cell (0,2)
8 is in cell (1,0)
1 is in Cell (1,1)
5 is in Cell (1,2)
2 is in Cell (2,0)
4 is in cell (2,1)
6 is in cell (2,2)
So in order to get the multiple cell reference
First i’ve Created numbers as List
Dim numbers As String() = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}
and by searching the above nos i get the multiple cell.Address Reference of DataGridview

I don’t know whether the below Function is Correct for the desired result.

After Getting the below list of all the Cell Address I would like to use the same cell Address for more datagridviews
What would you suggest to store the same in List or Array ?

Your help will be appreciated
Thanks SsD

Private Sub MultipleCells_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cellsList As New ArrayList

        For i As Integer = 1 To UBound(numbers)
            Dim cell = mulitpleGetCellAddress(DataGridView1, numbers(i))
            If cell IsNot Nothing Then
                'MessageBox.Show($"Data exists in cell ({cell.RowIndex}, {cell.ColumnIndex})")
                cellsList.Add($"", i & ({cell.RowIndex}, {cell.ColumnIndex})) '& ({cell.RowIndex}, {cell.ColumnIndex}))
            Else
                'MessageBox.Show("Data does not exist!")
            End If
            'i = i + 1
        Next
End Sub 
Private Function mulitpleGetCellAddress(dgv As DataGridView, searchString As String) As DataGridViewCell
    For Each row In dgv.Rows.OfType(Of DataGridViewRow)
        For Each cell In row.Cells.OfType(Of DataGridViewCell)
            If cell.Value.ToString() = searchString Then
                Return cell
            End If
        Next
    Next
    Return Nothing
End Function

made a Blunder in the line 
```cellsList.Add($"", i & ({cell.RowIndex}, {cell.ColumnIndex})) '& ({cell.RowIndex}, {cell.ColumnIndex})) ```

3

Since we’re iterating over a UI element, we would want to limit the number of iterations. Let’s use an iterator function returning all the matches, with each cell only being checked once – well the Any will stop checking once a match is found and even though both your idea and this one are O(n2), this one is so to a lesser degree.

Private Iterator Function mulitpleGetCellAddress(dgv As DataGridView, searchStrings As IEnumerable(Of String)) As IEnumerable(Of DataGridViewCell)
    For Each row In dgv.Rows.OfType(Of DataGridViewRow)
        For Each cell In row.Cells.OfType(Of DataGridViewCell)
            If searchStrings.Any(Function(s) cell.Value.ToString() = s) Then Yield cell
        Next
    Next
End Function

Now you will have a list of cells which match any of the sought items

Dim cells = mulitpleGetCellAddress(DataGridView1, numbers.Select(Function(n) $"{n}"))
If cells IsNot Nothing Then
    MessageBox.Show($"Data exists in cells {String.Join("; ", cells.Select(Function(c) $"({c.RowIndex}, {c.ColumnIndex})"))}")
Else
    MessageBox.Show("Data does not exist!")
End If

5

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật