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. Visual Basic
  4. How to perform non-case search in DataGridViewComboBoxColumn

How to perform non-case search in DataGridViewComboBoxColumn

Scheduled Pinned Locked Moved Visual Basic
helptestingbeta-testingregexxml
5 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.
  • M Offline
    M Offline
    mo1492
    wrote on last edited by
    #1

    Hello, I have added a DataGridViewComboBoxColumn to a DataGridView and i'm having a little problem. For testing I am loading one item in the combobox. The item value source is an xml filename without path or extension; ie. "Foodlion". The xml file has an entry that defines this filename but has a different case like "FoodLion". After loading the xml file and passing its' value "FoodLion" to the combobox, I get this context error in DataGridView1.DataError: Formatting, Display I'm not performing any formatting on this field since I expect just text. I get it that the combobox must be performing a FindExact() type search and does not match. Before I go through the pain staking effort to try an make sure the names match, is there something I can do change the combobox processing? Thanks

    C 1 Reply Last reply
    0
    • M mo1492

      Hello, I have added a DataGridViewComboBoxColumn to a DataGridView and i'm having a little problem. For testing I am loading one item in the combobox. The item value source is an xml filename without path or extension; ie. "Foodlion". The xml file has an entry that defines this filename but has a different case like "FoodLion". After loading the xml file and passing its' value "FoodLion" to the combobox, I get this context error in DataGridView1.DataError: Formatting, Display I'm not performing any formatting on this field since I expect just text. I get it that the combobox must be performing a FindExact() type search and does not match. Before I go through the pain staking effort to try an make sure the names match, is there something I can do change the combobox processing? Thanks

      C Offline
      C Offline
      CHill60
      wrote on last edited by
      #2

      Why not load the combobox using either the .ToLower() or .ToUpper() functions? Or if you want it to "look nice" you could always use the TextInfo.ToTitleCase(String) Method (System.Globalization)[^] method. In general the ComboBox.FindString Method[^] is not case-sensitive so I suspect this has nothing to do with a "FindExact() type search" but you have neither shared code nor the exact wording of the error so it's a little difficult to help further

      M 1 Reply Last reply
      0
      • C CHill60

        Why not load the combobox using either the .ToLower() or .ToUpper() functions? Or if you want it to "look nice" you could always use the TextInfo.ToTitleCase(String) Method (System.Globalization)[^] method. In general the ComboBox.FindString Method[^] is not case-sensitive so I suspect this has nothing to do with a "FindExact() type search" but you have neither shared code nor the exact wording of the error so it's a little difficult to help further

        M Offline
        M Offline
        mo1492
        wrote on last edited by
        #3

        Sorry for the confusion. The error from my post in more clear terms are: Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles MyBase.DataError { ' DataGridViewDataErrorContexts.Display ' DataGridViewDataErrorContexts.Formatting Debug.WriteLine(e.Context.ToString()) } My ComboBox code would not do you any good because it is full of structure data references which would not make sense to you but here is what causes the problem, hopefully more clear. When I initialize the DataGridView columns, for the combobox object I load the list value which is the filename of the source xml file which happens to be "Foodlion" (note case). Dim cmb As New DataGridViewComboBoxColumn() cmb.Items.Add("Foodlion") I then create a row with the value for the ComboBox which happens to be "FoodLion" (case difference) because that's the way it was originally created in the xml file. Me.Rows.Add(dataArray()) This causes the above error whenever the cell is Formatted by the DataGridView. Making sure the data and the combobox list item are the same case fixes the problem. So something in the DataGridView formatting doesn't like the case difference. Therefore that's why I 'assumed' that the ComboBox or underlying code was doing a case sensitive search; My Bad. Your Q. Why not load the combobox using either the .ToLower() or .ToUpper() functions? When the xml file is created the filename is saved in the xml data (in a particular case). The 'case' of the filename of the file that is stored on disk can change. When I enumerate the xml files on disk (Directory.GetFiles(path, "*.xml")), I use that filename to load into the combobox list as above (cmb.Items.Add("Foodlion"). If its' case is not the same as what is stored in the xml file, I get the DataError. I just asked the question in case someone may have encountered this type of issue with DataGridViewComboBoxColumn. I think I have found a work around 'HACK' by saving the filename in the xml file in a particular format and then formatting the filename from disk the same way. I hate to HACK code. Again, sorry for the confusion. :( Hope this is clearer. Thanks :)

        C 1 Reply Last reply
        0
        • M mo1492

          Sorry for the confusion. The error from my post in more clear terms are: Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles MyBase.DataError { ' DataGridViewDataErrorContexts.Display ' DataGridViewDataErrorContexts.Formatting Debug.WriteLine(e.Context.ToString()) } My ComboBox code would not do you any good because it is full of structure data references which would not make sense to you but here is what causes the problem, hopefully more clear. When I initialize the DataGridView columns, for the combobox object I load the list value which is the filename of the source xml file which happens to be "Foodlion" (note case). Dim cmb As New DataGridViewComboBoxColumn() cmb.Items.Add("Foodlion") I then create a row with the value for the ComboBox which happens to be "FoodLion" (case difference) because that's the way it was originally created in the xml file. Me.Rows.Add(dataArray()) This causes the above error whenever the cell is Formatted by the DataGridView. Making sure the data and the combobox list item are the same case fixes the problem. So something in the DataGridView formatting doesn't like the case difference. Therefore that's why I 'assumed' that the ComboBox or underlying code was doing a case sensitive search; My Bad. Your Q. Why not load the combobox using either the .ToLower() or .ToUpper() functions? When the xml file is created the filename is saved in the xml data (in a particular case). The 'case' of the filename of the file that is stored on disk can change. When I enumerate the xml files on disk (Directory.GetFiles(path, "*.xml")), I use that filename to load into the combobox list as above (cmb.Items.Add("Foodlion"). If its' case is not the same as what is stored in the xml file, I get the DataError. I just asked the question in case someone may have encountered this type of issue with DataGridViewComboBoxColumn. I think I have found a work around 'HACK' by saving the filename in the xml file in a particular format and then formatting the filename from disk the same way. I hate to HACK code. Again, sorry for the confusion. :( Hope this is clearer. Thanks :)

          C Offline
          C Offline
          CHill60
          wrote on last edited by
          #4

          Hopefully your hack will work but given that you are apparently doing a

          cmb.Items.Add("Foodlion")

          and

          Me.Rows.Add(dataArray())

          couldn't you do

          cmb.Items.Add(("Foodlion").ToLower)

          and

          Me.Rows.Add(dataArray.Select(c => c.ToLower()).ToArray())

          instead? (Apologies - I'm nowhere near Visual Studio and can't check whether my solution compiles let alone works! Hopefully you get the gist)

          M 1 Reply Last reply
          0
          • C CHill60

            Hopefully your hack will work but given that you are apparently doing a

            cmb.Items.Add("Foodlion")

            and

            Me.Rows.Add(dataArray())

            couldn't you do

            cmb.Items.Add(("Foodlion").ToLower)

            and

            Me.Rows.Add(dataArray.Select(c => c.ToLower()).ToArray())

            instead? (Apologies - I'm nowhere near Visual Studio and can't check whether my solution compiles let alone works! Hopefully you get the gist)

            M Offline
            M Offline
            mo1492
            wrote on last edited by
            #5

            Actually that's basically my hack except that the dataArray comes from my own xml class that loads the xmlfile data into variables (ie an array). The xml class formats the data and my custom DataGridView class loads from the xml class in the way you suggest. Thanks for you suggestion. :)

            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