Tracking number of open raddesktop alerts

6 posts, 1 answers
  1. John
    John avatar
    37 posts
    Member since:
    Jun 2010

    Posted 18 Jan 2011 Link to this post

    Hi I want to show only upto 3 desktop alerts at any given time.  Some alerts have autoclose options while others do not.  As such before displaying an alert, I need to check how many are open.  I tried using the desktopalertmanager but running into null exception errors

    Dim

     

    iDesktopAlertManager As DesktopAlertManager
    Dim value As IEnumerator(Of RadDesktopAlert)
    value = iDesktopAlertManager.GetRegisteredAlerts()

     

    I stepped though the code and the iDesktopAlertManager is nothing which causes a null exception error.  I am not fully aware of the DesktopAlertManager.

    This is similar to the code sample on your reference pages so not sure what I am doing wrong here...
    http://www.telerik.com/help/winforms/telerik.wincontrols.ui-telerik.wincontrols.ui.desktopalertmanager-getregisteredalerts.html
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 18 Jan 2011 Link to this post

    Hello John,

    Please can you try this in a new project. It's just a form and a RadButton

    Private m_Alerts As New List(Of Telerik.WinControls.UI.RadDesktopAlert)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Alert_Closed(ByVal Sender As Object, ByVal e As EventArgs)
        m_Alerts.Remove(CType(Sender, Telerik.WinControls.UI.RadDesktopAlert))
    End Sub
    Private Sub ButtonGenerateAlert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGenerateAlert.Click
        If m_Alerts.Count < 3 Then
            Dim alert As New Telerik.WinControls.UI.RadDesktopAlert()
            alert.CaptionText = "Alert Header"
            alert.ContentText = "Alert Context"
            m_Alerts.Add(alert)
            alert.Show()
            AddHandler alert.Closed, AddressOf Alert_Closed
        End If
    End Sub

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 20 Jan 2011 Link to this post

    Hello,

    Did this help? If so please remember to mark as answer. If you need morre assistance just let me know.
    Regards,
    Richard
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 21 Jan 2011 Link to this post

    Hello John,

    Here is the proper way to use the DesktopAlertManager to get the count of the shown alerts:
    Public Function GetAlertCount() As Integer
        Dim count As Integer = 0
        Dim alerts As IEnumerator(Of RadDesktopAlert) = DesktopAlertManager.Instance.GetRegisteredAlerts()
        While alerts.MoveNext()
            count += 1
        End While
     
        Return count
    End Function

    Richard's approach could also do the required task.

    I hope this was helpful. Should you have any further questions, do not hesitate to ask.

    Greetings,
    Ivan Todorov
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  6. John
    John avatar
    37 posts
    Member since:
    Jun 2010

    Posted 25 Jan 2011 Link to this post

    I will try this option and update with my findings.
  7. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 28 Jan 2011 Link to this post

    Hi John,

    Please let us know if this worked for you, when you try it. I will be glad to assist you if you need further help, so do not hesitate to write back.

    Greetings,
    Ivan Todorov
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Back to Top
UI for WinForms is Visual Studio 2017 Ready