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. FindNext on BindingSource

FindNext on BindingSource

Scheduled Pinned Locked Moved C#
data-structuresquestion
2 Posts 1 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.
  • J Offline
    J Offline
    jchalfant
    wrote on last edited by
    #1

    Anyone know a good method for implementing a findnext-ish function on a BindingSource? bindingSourceObject.Find works great for finding single rows but won't find the next value. I'm thinking maybe declaring a DataRow array and assigning its value with dataTableObject.Select. Once I do that I use bindingSourceObject.IndexOf(dataRowArray[nextindex]) to get the desired position of the next row. Does anyone have any better, more efficient ideas? If so, I'd like to hear them.

    J 1 Reply Last reply
    0
    • J jchalfant

      Anyone know a good method for implementing a findnext-ish function on a BindingSource? bindingSourceObject.Find works great for finding single rows but won't find the next value. I'm thinking maybe declaring a DataRow array and assigning its value with dataTableObject.Select. Once I do that I use bindingSourceObject.IndexOf(dataRowArray[nextindex]) to get the desired position of the next row. Does anyone have any better, more efficient ideas? If so, I'd like to hear them.

      J Offline
      J Offline
      jchalfant
      wrote on last edited by
      #2

      I guess I was on the right track. Here's the code that makes it work. BindingSource _mainBS; string _fieldname; TARData.TARDataSet.DataRow[] _mRA; string _searchstring; int _currentPosition; _mainBS is assigned by a constructor, likewise _fieldname. public void FindNext() { if (_searchstring != textBox1.Text) { _searchstring = textBox1.Text; _currentPosition = 0; string searchCrit = getColumnSearchString(((DataRowView)_mainBS.Current).DataView.Table.Columns[_fieldname].DataType); _mRA = (TARData.TARDataSet.Carter_TAR_MainRow[])((DataRowView)_mainBS.Current).DataView.Table.Select( searchCrit + " LIKE '%" + _searchstring + "%'"); } if (_mRA.Length > 0) { this._mainBS.Position = this._mainBS.Find("Main_ID", _mRA[_currentPosition]["Main_ID"]); ; } _currentPosition = (_currentPosition + 1) % _mRA.Length; } Just in case _fieldname is an int type, I throw in this little tidbit to perform a convert. private string getColumnSearchString(Type type) { if (type == typeof(int)) return "Convert(" + _fieldname + ",System.String)"; else return _fieldname; } Not too efficient, but I still like admiring it. Not a bad way to spend an hour of my day.

      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