Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to detect invalid character input in ListView control?

How to detect invalid character input in ListView control?

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShadowUz
    wrote on last edited by
    #1

    How to detect invalid character input in ListView control? I want to detect invalid character input while editing a ListBox's item and show a tooltip with warning. I know how to do it for TextBox control:

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    ToolTip myTooltip = new ToolTip();
    if (textBox1.Text.Contains("Invalid Character"))
    {
    myTooltip.Show("You entered an invalid character", textBox1);
    }
    }

    How to make it for a ListBox control? Thank you.

    M 1 Reply Last reply
    0
    • S ShadowUz

      How to detect invalid character input in ListView control? I want to detect invalid character input while editing a ListBox's item and show a tooltip with warning. I know how to do it for TextBox control:

      private void textBox1_TextChanged(object sender, EventArgs e)
      {
      ToolTip myTooltip = new ToolTip();
      if (textBox1.Text.Contains("Invalid Character"))
      {
      myTooltip.Show("You entered an invalid character", textBox1);
      }
      }

      How to make it for a ListBox control? Thank you.

      M Offline
      M Offline
      Mario Majcica
      wrote on last edited by
      #2

      Try with ListView.BeforeLabelEdit Event. http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.beforelabeledit.aspx[^]

      S 1 Reply Last reply
      0
      • M Mario Majcica

        Try with ListView.BeforeLabelEdit Event. http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.beforelabeledit.aspx[^]

        S Offline
        S Offline
        ShadowUz
        wrote on last edited by
        #3

        Thank you for the reply. But I can't make use of this method as I need a real-time check for user input.

        M 1 Reply Last reply
        0
        • S ShadowUz

          Thank you for the reply. But I can't make use of this method as I need a real-time check for user input.

          M Offline
          M Offline
          Mario Majcica
          wrote on last edited by
          #4

          You can combine two events to achieve the goal. First create a flag, like isEditing = false; On BeforeLabelEdit Event change it to true, meanwhile on AfterLabelEdit Event change it to false. Then on KeyDown Event check first if isEditing == true, then process the key. May this be the solution? EDIT: On BeforeLabelEdit Event you can store the value and on AfterLabelEdit Event get the value and see if it is changed then rise an custom event? Can this be a better way?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups