Wendys Art Ответов: 0

Динамическое добавление datagridviewcolumns с помощью 2 datetimepicker


Всем привет... у меня есть проблема, когда я пытаюсь сделать динамическое добавление datagridviewcolumns на языке visual basic. таким образом, столбцы будут добавляться при изменении выбранного значения даты начала или даты окончания.

Что я уже пробовал:

мой код таков :


Sub LoadFormatgvPanelRoomRack()

        gvPanelRoomRack.Columns.Clear()
        gvPanelRoomRack.Rows.Clear()

        Dim pTimeCI As DateTime
        Dim pTimeCO As DateTime

        Try
            con.Close()
            con.Open()
            strSql = "SELECT tp_tblsttimerangesetting.KdTRS," & _
                            "tp_tblsttimerangesetting.CITime," & _
                            "tp_tblsttimerangesetting.COTime," & _
                            "tp_tblsttimerangesetting.KdActiveStatus" & _
                     " FROM tp_tblsttimerangesetting" & _
                     " WHERE tp_tblsttimerangesetting.KdActiveStatus=1"
            cmd = New MySqlCommand(strSql, con)
            dr = cmd.ExecuteReader
            dr.Read()
            If dr.HasRows Then
                pTimeCI = dr.Item(1).ToString
                pTimeCO = dr.Item(2).ToString
            End If
            dr.Close()
            dr.Dispose()
        Catch ex As Exception
            Beep()
            'MessageBox.Show("Terjadi kesalahan dalam pengambilan data room", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
            MsgBox("Error LoadDataOccupancy: " & ex.Message)
        Finally
            con.Close()
            con.Dispose()
        End Try

        pTimeCI = pTimeCI.ToLongTimeString
        pTimeCO = pTimeCO.ToLongTimeString


        Dim pDateCI As Date
        Dim pDateCO As Date

        If dtpStart.Text = "" Then
            pDateCI = Now
        Else
            pDateCI = dtpStart.Text
        End If
        If dtpEnd.Text = "" Then
            pDateCO = Now.AddDays(3)
        Else
            pDateCO = dtpEnd.Text
        End If

        Dim selisih As Integer
        selisih = DateDiff(DateInterval.Day, pDateCI, pDateCO)
        TextBox2.Text = selisih + 1

        With gvPanelRoomRack
            .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
            .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
            .ColumnHeadersHeight = 40
            .RowHeadersWidth = 41

            Dim colRoomNumber As New DataGridViewButtonColumn()
            With colRoomNumber
                .Name = "RoomNumber"
                .HeaderText = "No."
                .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .SortMode = DataGridViewColumnSortMode.NotSortable
                .FlatStyle = FlatStyle.Standard
            End With
            .Columns.Add(colRoomNumber)

            Dim colRoomType As New DataGridViewButtonColumn()
            With colRoomType
                .Name = "RoomType"
                .HeaderText = "R. Type"
                .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .SortMode = DataGridViewColumnSortMode.NotSortable
                .FlatStyle = FlatStyle.Standard
            End With
            .Columns.Add(colRoomType)

            Dim colBedType As New DataGridViewButtonColumn()
            With colBedType
                .Name = "BedType"
                .HeaderText = "Bed"
                .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .SortMode = DataGridViewColumnSortMode.NotSortable
                .FlatStyle = FlatStyle.Standard
            End With
            .Columns.Add(colBedType)

            Dim colToday As New DataGridViewButtonColumn()
            With colToday
                .Name = "Today"
                .HeaderText = "Today"
                .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .SortMode = DataGridViewColumnSortMode.NotSortable
                .FlatStyle = FlatStyle.Standard
            End With
            .Columns.Add(colToday)

            Dim colCIDate As New DataGridViewTextBoxColumn()
            With colCIDate
                .Name = "CIDate"
                .HeaderText = (Format(pDateCI, "yyyy/MM/dd") & " " & pTimeCI)
                .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .SortMode = DataGridViewColumnSortMode.NotSortable
            End With
            .Columns.Add(colCIDate)


            Dim colCODate As New DataGridViewTextBoxColumn()
            With colCODate
                .Name = "CODate"
                .HeaderText = (Format(pDateCI.AddDays(1), "yyyy/MM/dd") & " " & pTimeCO)
                .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .SortMode = DataGridViewColumnSortMode.NotSortable
            End With
            .Columns.Add(colCODate)

            Do Until pDateCI = pDateCO.AddDays(-1)
                pDateCI = pDateCI.AddDays(1)
                .Columns.Add((Format(pDateCI, "yyyyMMddHHmmss")), (Format(pDateCI, "yyyy/MM/dd") & " " & pTimeCI))
                .Columns.Add((Format(pDateCI.AddDays(1), "yyyyMMddHHmmss")), (Format(pDateCI.AddDays(1), "yyyy/MM/dd") & " " & pTimeCO))
            Loop

            .GridColor = Color.Blue
            .DefaultCellStyle.ForeColor = Color.Black
            .RowsDefaultCellStyle.BackColor = Color.WhiteSmoke
            .AlternatingRowsDefaultCellStyle.BackColor = Color.White
            .GridColor = Color.Silver

        End With

    End Sub





с погрешностью:
Сумма значений веса заполнения столбцов не может превышать 65535.
в циклической линии (
.Columns.Add((Format(pDateCI.AddDays(1), "yyyyMMddHHmmss")), (Format(pDateCI.AddDays(1), "yyyy/MM/dd") & " " & pTimeCO)))

)

как я могу решить эту проблему, пожалуйста...
спасибо

0 Ответов