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. Data binding using checkbox

Data binding using checkbox

Scheduled Pinned Locked Moved C#
databasequestionwpfwcf
2 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.
  • C Offline
    C Offline
    coolzzzz
    wrote on last edited by
    #1

    Hi all, I have a question would like to ask regards to the complex data binding using checkbox control. My situation was my data types at SQL database was char data types and it holds only 'Y' and 'N' value. Now I would like to bind the char datatypes 'Y'/'N' to the checkbox control. When the values hold for 'Y' and checkbox will be checked. Otherwise, it was in uncheck mode. If the values holds for other data values beside 'Y' / 'N', an intermediate checkbox value will be holded. whatever method being tried before, it can't bind correctly onto the checkbox control, is there any method I can bind it correctly using char data types by using checkbox control?:( Steven Leong

    H 1 Reply Last reply
    0
    • C coolzzzz

      Hi all, I have a question would like to ask regards to the complex data binding using checkbox control. My situation was my data types at SQL database was char data types and it holds only 'Y' and 'N' value. Now I would like to bind the char datatypes 'Y'/'N' to the checkbox control. When the values hold for 'Y' and checkbox will be checked. Otherwise, it was in uncheck mode. If the values holds for other data values beside 'Y' / 'N', an intermediate checkbox value will be holded. whatever method being tried before, it can't bind correctly onto the checkbox control, is there any method I can bind it correctly using char data types by using checkbox control?:( Steven Leong

      H Offline
      H Offline
      Hayder Marzouk
      wrote on last edited by
      #2

      Hi, This can be resolved using Format/Parse handlers. Here the code : Binding YesNoBinding = new Binding("Checked", yourDatasource, "YourPropertyName", false, DataSourceUpdateMode.OnPropertyChanged); YesNoBinding.Format += new ConvertEventHandler(YesNoBinding_Format); YesNoBinding.Parse += new ConvertEventHandler(YesNoBinding_Parse); yourCheckBox.DataBindings.Add(YesNoBinding); And here the code for handlers : void YesNoBinding_Parse(object sender, ConvertEventArgs e) { if ((bool)e.Value == true) e.Value = "Y"; else e.Value = "N"; } void YesNoBinding_Format(object sender, ConvertEventArgs e) { if ((string) e.Value == "Y") e.Value = true; else e.Value = false; } HTH. Hayder Marzouk

      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