0

The code below does not work, the error says the method ValidateSettings does not have a signature compatable with delgate 'Delgate Sub SettingChangingEventHandler(sender as Object, e as SettingChangingEventArgs)'

This error shows up when hovering over [...] AddressOf ValidateSettings

    Private Sub ValidateSettings(sender As Object, e As SettingChangingEventArgs)


    End Sub

    Private Sub frm_Settings_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        AddHandler My.Settings.SettingChanging, AddressOf ValidateSettings
        PropertyGrid_Settings.SelectedObject = My.Settings
        CenterToParent()
    End Sub

Im using this tutorial

  • Have you added `Imports System.Configuration` on top of your class? – Jimi Feb 16 '20 at 00:47
  • Nope, i didnt have it, it works now, thank you! btw how did you know? It doesnt mention this anywhere on the microsoft page. – Bartekchrup Feb 16 '20 at 09:22
  • It's mentioned in the first part of the document you linked: *ApplicationSettingsBase, the parent class of all application settings classes, exposes four events (...)*. `ApplicationSettingsBase` belongs to the `System.Configuration` assembly. Also, it's used quite often :) – Jimi Feb 16 '20 at 14:29

1 Answers1

1

The solution was to add Imports System.Configuration to the class, as pointed out by a comment on the original post.

Imports System.Configuration
Public Class frm_Settings

    Private Sub ValidateSettings(sender As Object, e As SettingChangingEventArgs)
        'validation and notifying user
        MsgBox(e.NewValue)
    End Sub

    Private Sub frm_Settings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler My.Settings.SettingChanging, AddressOf ValidateSettings
        PropertyGrid_Settings.SelectedObject = My.Settings

        CenterToParent()
    End Sub