Copyright Codenstuff.com 2017
YOU NEED TO BE LOGGED IN TO USE THIS FEATURE


Register
Credits
0
Reputation
0
Replace Controls with other data?
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.


Replace Controls with other data?
Hello,

working on it but can't replace them :(
i like to replace the existing controls in a listbox
but what do we wrong?

'loading the controls
Code: Select all
    Public Sub LOadingEvents()
        Try

            Dim attributes As String = "defaultstatus,statuscolor"

            ' ''if specifying a class id, create appropriate query
            Dim empls As SQLiteDataReader = Database.executeQuery("SELECT " & attributes & " FROM colors ORDER BY defaultstatus DESC;")

            While empls.Read() = True

                Dim items As String() = New String(10) {}
                items(0) = empls.GetValue(0).ToString
                items(1) = empls.GetValue(1).ToString

                Dim item As New SkinEventBar

                If (Not String.IsNullOrEmpty(items(0))) Then

                    For i = 1 To 1 Step 1

                        With item
                            Dim str As [String] = items(1)
                            Dim clrConverter As New ColorConverter()
                            .Description = items(0)
                            .EventColor = DirectCast(clrConverter.ConvertFromString(str), Color)
                            .Countevents = 0
                            .Dock = DockStyle.Top
                            .Refresh()
                        End With
                    Next

                End If
                Me.Invoke(New InsertEventBar(AddressOf Me.Insertprogress), item)
            End While
        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Private Delegate Sub InsertEventBar(ByVal lvi As SkinEventBar)
    Private Sub Insertprogress(ByVal lvi As SkinEventBar)
        lblevent.Controls.Add(lvi)
    End Sub



'We want to replace the existing .countevents
Code: Select all
Public Sub ReplaceThem()
For Each itm As Control In lblevent.Controls
                            For Each c As Control In itm.Controls
                                If TypeOf c Is SkinEventBar Then
                                    CType(c, SkinEventBar).Countevents =60
                                    CType(c, SkinEventBar).Refresh()
                                End If
                            Next
                        Next
End Sub


Anyone please

Thanks

Do you have a property in your custom control like this:

Code: Select all
    Public Counter As Integer = 0

    Property Countevents As Integer
        Get
            Return Counter
        End Get
        Set(ByVal value As Integer)
            If Not Counter = value Then
                Counter = value
                Label1.Text = Counter.ToString
            End If
        End Set
    End Property


That should update the info and in the example would update the label like:

Code: Select all
MyCustomControl.Countevents += 1

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Re: Replace Controls with other data?
Hello Cns,

O yea we have the same class
but we load our controls into the listbox first and then we load other data to get the countevents
because no idea how to load everything into 1 load?
but how do we replace the existing controls in our listbox to change the countevents?

loading the events first:
Code: Select all
    Public Sub LOadingEvents()
        Try

            Dim attributes As String = "defaultstatus,statuscolor"

            ' ''if specifying a class id, create appropriate query
            Dim empls As SQLiteDataReader = Database.executeQuery("SELECT " & attributes & " FROM colors ORDER BY defaultstatus DESC;")

            While empls.Read() = True

                Dim items As String() = New String(10) {}
                items(0) = empls.GetValue(0).ToString
                items(1) = empls.GetValue(1).ToString

                Dim item As New SkinEventBar

                If (Not String.IsNullOrEmpty(items(0))) Then

                    For i = 1 To 1 Step 1

                        With item
                            Dim str As [String] = items(1)
                            Dim clrConverter As New ColorConverter()
                            .Description = items(0)
                            .EventColor = DirectCast(clrConverter.ConvertFromString(str), Color)
                            .Countevents = 0
                            .Dock = DockStyle.Top
                            .Refresh()
                        End With
                    Next

                End If
                Me.Invoke(New InsertEventBar(AddressOf Me.Insertprogress), item)
            End While
        Catch ex As Exception
            Exit Sub
        End Try

    End Sub

    Private Delegate Sub InsertEventBar(ByVal lvi As SkinEventBar)
    Private Sub Insertprogress(ByVal lvi As SkinEventBar)
        lblevent.Controls.Add(lvi)
    End Sub



loading to get the counts
Code: Select all
Dim attributes As String = "scheduler.eventid,colors.statuscolor,colors.defaultstatus,count(eventid)"
            ' ''if specifying a class id, create appropriate query
            Dim whereClause As String = "scheduler.id='" & id & "' AND scheduler.monthid='" & monthid & "' AND scheduler.yearid='" & yearid & "'"

            Dim fromClause As String = "LEFT JOIN colors ON scheduler.eventid = colors.colorid"

            Dim empls As SQLiteDataReader = Database.executeQuery("SELECT " & attributes & " Relation FROM scheduler " & fromClause & " WHERE " & whereClause & " GROUP BY scheduler.eventid;")

            While empls.Read() = True

                Dim items As String() = New String(10) {}
                items(0) = empls.GetValue(0).ToString
                items(1) = empls.GetValue(1).ToString
                items(2) = empls.GetValue(2).ToString
                items(3) = empls.GetValue(3).ToString

                If (Not String.IsNullOrEmpty(items(0))) Then

                    For i = 1 To 1 Step 1

                        For Each itm As Control In lblevent.Controls
                            For Each c As Control In itm.Controls
                                If TypeOf c Is SkinEventBar Then
                                    CType(c, SkinEventBar).Countevents = items(3)
                                    CType(c, SkinEventBar).Refresh()
                                End If
                            Next
                        Next
                    Next


this is our controls with the countevents
Image

Re: Replace Controls with other data?
:crying;
i tried it with an array but only get 1 record

so if anyone can find a solution i like to hear :)

thanks

Merry Christmas my friends

Re: Replace Controls with other data?
I'm not sure how to help you on this one, bit busy at the moment with it being Christmas.

But having a quick look at the code what is this for:

Code: Select all
For i = 1 To 1 Step 1


Is that not updating just the one control?

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Re: Replace Controls with other data?
First of all Happy New Year to you all :)

After long trying we have solved it and we get some results
but its strange we don't get everything??

when we have a few days on the planner we get every result
but when we have a complete month we only get a few results

this is from December 2016 as you can see its not count everything
Image

this is from January 2017 as you can see it counts everything
Image

still no idea why?

our updated code:
this code loads everytime we got to a new month and fill out our results in the calendar

Code: Select all
 Public Sub LoadRTBTextFile(ByVal RTB As RichTextBox, ByVal DayNumber As Integer)
For Each itm As Control In EnumerateAllControls(Me)
                For Each c As Control In itm.Controls
                    If TypeOf c Is SkinDate Then
                        If c.Name = RTB.Name Then

                            Dim attributes As String = "employees.employeeid,scheduler.setdate,scheduler.StartTime,scheduler.EndTime, employees.name,employees.firstname,colors.statuscolor,colors.defaultstatus,scheduler.note,scheduler.eventid,count(scheduler.eventid) Relation"

                            Dim whereClause As String = "scheduler.id='" & SetEmployeeID & "' AND scheduler.setdate ='" & LabelMonth.Text & DayNumber & LabelYear.Text & "'"

                            Dim fromClause As String = "left JOIN employees ON employees.employeeid = scheduler.id left JOIN colors ON colors.colorid = scheduler.eventid"

                            Dim empls As SQLiteDataReader = Database.executeQuery("SELECT " & attributes & " FROM scheduler " & fromClause & " WHERE " & whereClause & " ;")

                            While empls.Read() = True

                                Dim items As String() = New String(8) {}

                                items(0) = empls.GetValue(0).ToString 'employee id
                                items(1) = empls.GetValue(1).ToString 'setdate
                                items(2) = empls.GetValue(2).ToString 'StartTime
                                items(3) = empls.GetValue(3).ToString 'EndTime

                                items(4) = empls.GetValue(6).ToString 'color
                                items(5) = empls.GetValue(7).ToString 'defaultevent
                                items(6) = empls.GetValue(8).ToString 'note

                                items(7) = empls.GetValue(9).ToString 'colorid
                                items(8) = empls.GetValue(10).ToString 'count

                                If Not items(0).ToString = String.Empty Then

                                    Dim str As [String] = items(4).ToString
                                    Dim clrConverter As New ColorConverter()
                                    Class1.newcol = DirectCast(clrConverter.ConvertFromString(str), Color)

                                    CType(c, SkinDate).l2.Description = items(5).ToString
                                    CType(c, SkinDate).l2.EventColor = Class1.newcol
                                    CType(c, SkinDate).StartTime = items(2).Remove(4, 3)
                                    CType(c, SkinDate).EndTime = items(3).Remove(4, 3)
                                    CType(c, SkinDate).Notes = items(6)
                                    CType(c, SkinDate).l1.EventColor = Color.FromArgb(58, 58, 58)
                                    CType(c, SkinDate).l1.Description = items(2).Remove(4, 3) & " - " & items(3).Remove(4, 3)

                                    LoadContacts(items(7), items(8))
                                End If
                            End While
                            empls.Close()
                        End If
                    End If
                Next
            Next


Code: Select all
Sub LoadContacts(ByVal Category As String, ByVal setcount As Integer)
        For Each Ctl In FrmCalendar.lblevent.Controls
            If TypeOf Ctl Is SkinEventBar Then
                With Ctl
                    If Ctl.tag = Category Then 'if tag and catergory has the same colorid then we add the count
                        Ctl.countevents += setcount
                        Ctl.refresh
                    End If
                End With
            End If
        Next
    End Sub


Any help please?

Re: Replace Controls with other data?
I just had a quick look and I noticed in the calendar that "Holiday" and "Leave" don't have any times on them.

Those are the only ones that don't seem to be counted so could it be because they have no End Time or Start Time? :duh;

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Re: Replace Controls with other data?
Hello Codenstuff,

o my god...
you are absolutely correct i have added a time and it seems it counts :waaa;
well thanks codenstuff
you are amazing

Regards

Dummy




Online now

Users viewing this forum: No registered users and 1 browsing