datagridview添加了许多行问题 [英] datagridview adds many rows problem

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

问题描述

我有一个数据网格连接到一个带有ADO .Net的数据库,当我执行代码时,它将行添加到第二个数据网格,因为单元格的数量为米色,我想添加一行和颜色的单元格米色(他们符合要求并变成背景颜色米色,这是一个日期检查代码),它不添加1行和所选单元格,但每个选定的单元格只有1行,即使它们在同一行,我想要1行为一第一个datagridview的一行,我知道它在某些地方已经出现了但无法弄明白的地方。

在第二个datagridview中创建行的代码

I have a datagrid connected to a database with ADO .Net, when I execute the code it adds rows to the 2nd datagrid as the number of cells are in style beige, I want to add one row and the cells that in color beige (they meet the requirment and become backcolor beige, it is a date check code), it adds not 1 row and the selected cells but 1 row for each selected cell even if they are in the same row, I want 1 row for one row of the 1st datagridview, I know it is somewhere in the fro statments but cannot figure it out where.
code of creating rows in 2nd datagridview

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim c, t, d, g, h, i As Integer
       Form2.DataGridView1.Columns.Clear()
        For t = 0 To DataGridView1.Columns.Count - 1
            Form2.DataGridView1.Columns.Add(DataGridView1.Columns(t).Clone())
        Next
        c = 0
        d = 0
        For c = 0 To DataGridView1.Rows.Count - 1
            For d = 0 To DataGridView1.Rows(c).Cells.Count - 1
                If DataGridView1.Rows(c).Cells(d).Style.BackColor = Color.Beige Then
                    Form2.DataGridView1.Rows.Add(Me.DataGridView1.Rows(c).Cells(0).Value, Me.DataGridView1.Rows(c).Cells(1).Value, Me.DataGridView1.Rows(c).Cells(2).Value, Me.DataGridView1.Rows(c).Cells(3).Value, Me.DataGridView1.Rows(c).Cells(4).Value, Me.DataGridView1.Rows(c).Cells(5).Value, Me.DataGridView1.Rows(c).Cells(6).Value, Me.DataGridView1.Rows(c).Cells(7).Value, Me.DataGridView1.Rows(c).Cells(8).Value, Me.DataGridView1.Rows(c).Cells(9).Value, Me.DataGridView1.Rows(c).Cells(10).Value, Me.DataGridView1.Rows(c).Cells(11).Value, Me.DataGridView1.Rows(c).Cells(12).Value, Me.DataGridView1.Rows(c).Cells(13).Value)
                                  End If
            Next
        Next
end sub





和日期检查代码如果nessecary:



and code for date check if nessecary:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim dt As New Date
        Dim i, g As New Int32
        i = 0
        g = 0
        Dim workTable As DataTable = New DataTable("Customers")
        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
                i = i + 1
           End If
           End If
         Next
        Next
  MessageBox.Show("ΥΠΑΡΧΟΥΝ : " + i.ToString + " ΕΓΓΡΑΦΕΣ ΣΤΑ ΑΥΤΟΚΙΝΗΤΑ", "ΗΜΕΡΟΜΗΝΙΑ EXPIRED")
end sub

推荐答案

这篇关于datagridview添加了许多行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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