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. Databinding to the correct Row

Databinding to the correct Row

Scheduled Pinned Locked Moved C#
helpquestion
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.
  • D Offline
    D Offline
    Drew McGhie
    wrote on last edited by
    #1

    I have a small form that I spawn from another that acts as a way to edit a row of data from a typed DataTable. Within the load() method of the form, I execute this code. mySource = new BindingSource(); mySource.DataSource = myManagerClient.VersionTable; uxcbFMonth.DataBindings.Add("SelectedValue", mySource, "FiscalMonth"); uxtextFYear.DataBindings.Add("Text", mySource, "FiscalYear"); uxtextName.DataBindings.Add("Text", mySource, "VersionName"); uxcbType.DataBindings.Add("SelectedValue", mySource, "Type"); That works just fine and the data is all bound correctly. The problem is that it defaults to the first row of data in the sorted bindingsource. I have a foreign key value for the datarow I want to display, and I know I need to use the BindingSource.Position property to properly set the position I want to edit, but I'm having problems correctly finding the value to pass. I tried using mySource.IndexOf(/*The DataRow using myManagerClient.VersionTable.Select()*/), that returned -1. I also tried to use mySource.Filter(), but that filters the data in the main form as well (since I'm using Form.Show() instead of Form.ShowDialog()), and visually, I think that will confuse the end-user. As far as I can tell at the moment, I'm going to have to manually pass through each row until I find the right one, but there really seems like there might be an easy way that I'm just missing. Any ideas?

    D 1 Reply Last reply
    0
    • D Drew McGhie

      I have a small form that I spawn from another that acts as a way to edit a row of data from a typed DataTable. Within the load() method of the form, I execute this code. mySource = new BindingSource(); mySource.DataSource = myManagerClient.VersionTable; uxcbFMonth.DataBindings.Add("SelectedValue", mySource, "FiscalMonth"); uxtextFYear.DataBindings.Add("Text", mySource, "FiscalYear"); uxtextName.DataBindings.Add("Text", mySource, "VersionName"); uxcbType.DataBindings.Add("SelectedValue", mySource, "Type"); That works just fine and the data is all bound correctly. The problem is that it defaults to the first row of data in the sorted bindingsource. I have a foreign key value for the datarow I want to display, and I know I need to use the BindingSource.Position property to properly set the position I want to edit, but I'm having problems correctly finding the value to pass. I tried using mySource.IndexOf(/*The DataRow using myManagerClient.VersionTable.Select()*/), that returned -1. I also tried to use mySource.Filter(), but that filters the data in the main form as well (since I'm using Form.Show() instead of Form.ShowDialog()), and visually, I think that will confuse the end-user. As far as I can tell at the moment, I'm going to have to manually pass through each row until I find the right one, but there really seems like there might be an easy way that I'm just missing. Any ideas?

      D Offline
      D Offline
      Drew McGhie
      wrote on last edited by
      #2

      Found it, I needed to change the second line above to include .Select().

      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