选择一个选定的datagridview单元格行 [英] select a selected datagridview cell row

查看:67
本文介绍了选择一个选定的datagridview单元格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在datagridview中选择一个选定的单元格行,所选单元格有米色,代码为米色单元格:

I want to select a selected cell row in a datagridview, the selected cell has color beige, code to color beige cell :

Dim dt As New Date
           For Each row As DataGridViewRow In DataGridView1.Rows

               For c As Int32 = 1 To DataGridView1.ColumnCount - 1
                   If row.Cells(c).Value IsNot DBNull.Value Then
                   dt = Date.Parse(row.Cells(c).Value)
                   If (Date.Today >= (dt.AddMonths(-1))) And (Date.Today <= dt) Then
                    row.Cells(c).Style.BackColor = Color.Beige
             messageBox.Show("ΥΠΑΡΧΕΙ ΕΓΓΡΑΦΗ ΣΤΑ ΑΥΤΟΚΙΝΗΤΑ", "ΗΜΕΡΟΜΗΝΙΑ EXPIRED")
                    End If
                   End If
               Next
           Next



此代码使它的日期匹配例程的单元格成为bc.beige并且有效。现在我正在尝试将具有颜色为米色的单元格的行添加到数据表并将数据表作为新数据网格视图的源,我不知道如何使单元格的行被选中此代码无效:


this code makes the cell that its date matches the routine to become bc.beige and works. Now I am trying to make the row(s) that have cell with color beige to be selected add them to a datatable and st the datatable as source of a new datagridview, I don't know how to make the cell's row to be selectedm this code is not working :

For h As Integer = 0 To DataGridView1.Rows.Count - 1
          For d As Int32 = 1 To DataGridView1.ColumnCount - 1
            If DataGridView1.Rows(h).Cells(d).Style.BackColor = Color.Beige Then
              DataGridView1.Rows(h).Selected = True
              MessageBox.Show("rows " + h + " added", "rows")
              End If
          Next
        Next





任何帮助,谢谢。



Any help thank you.

推荐答案

根据我的评论 - 我质疑为什么OP踩着通过DataGridView的行和列 2 而不是DataGridView 1



OP证实这是解决方案。

感谢Nelek让我知道
As per my comment - I questioned why OP was stepping through the rows and columns of DataGridView2 instead of DataGridView1

OP confirmed that this was the solution.
Thanks to Nelek for letting me know


这篇关于选择一个选定的datagridview单元格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆