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. WPF
  4. wpf

wpf

Scheduled Pinned Locked Moved WPF
wpfcsharpwcfquestion
8 Posts 4 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.
  • A Offline
    A Offline
    arkiboys
    wrote on last edited by
    #1

    I have populated a combo box as follows: <ComboBox Height="23" HorizontalAlignment="Left" Margin="120,6,0,0" Name="cboHealth" SelectedIndex="{Binding Path=HealthLevelID}" VerticalAlignment="Top" Width="256" /> private void PopulateHealthLevels() { List<clsDetails> healthlevels = new List<clsDetails>(); healthlevels = clsAccess.GetHealthLevels(); foreach (clsDetails details in healthlevels) { cboHealth.Items.Add(details.HealthLevelName); } } The datatable returns the HealthLevelID field as well as otherr fields. HealthLevelID has values of 1 and 2 for Normal and unNormal respectively. The combo box does get populated but it does not show the correct item for the selected row. What am I doing wrong please? Thanks

    P R R 3 Replies Last reply
    0
    • A arkiboys

      I have populated a combo box as follows: <ComboBox Height="23" HorizontalAlignment="Left" Margin="120,6,0,0" Name="cboHealth" SelectedIndex="{Binding Path=HealthLevelID}" VerticalAlignment="Top" Width="256" /> private void PopulateHealthLevels() { List<clsDetails> healthlevels = new List<clsDetails>(); healthlevels = clsAccess.GetHealthLevels(); foreach (clsDetails details in healthlevels) { cboHealth.Items.Add(details.HealthLevelName); } } The datatable returns the HealthLevelID field as well as otherr fields. HealthLevelID has values of 1 and 2 for Normal and unNormal respectively. The combo box does get populated but it does not show the correct item for the selected row. What am I doing wrong please? Thanks

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      A couple of things here. 1. Your title needs some work. Simply stating wpf is not enough. 2. The code should be enclosed in pre tags. Now, your problem lies in the fact that SelectedIndex is actually zero based, so your values will not match. SelectedIndex should only be used to indicate the relative position of the object in your collection.

      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      A 2 Replies Last reply
      0
      • A arkiboys

        I have populated a combo box as follows: <ComboBox Height="23" HorizontalAlignment="Left" Margin="120,6,0,0" Name="cboHealth" SelectedIndex="{Binding Path=HealthLevelID}" VerticalAlignment="Top" Width="256" /> private void PopulateHealthLevels() { List<clsDetails> healthlevels = new List<clsDetails>(); healthlevels = clsAccess.GetHealthLevels(); foreach (clsDetails details in healthlevels) { cboHealth.Items.Add(details.HealthLevelName); } } The datatable returns the HealthLevelID field as well as otherr fields. HealthLevelID has values of 1 and 2 for Normal and unNormal respectively. The combo box does get populated but it does not show the correct item for the selected row. What am I doing wrong please? Thanks

        R Offline
        R Offline
        Renat Khabibulin
        wrote on last edited by
        #3

        Seems that ComboBox doesnt know that HealthLevelID was changed, try this:

        BindingExpression binding = BindingOperations.GetBindingExpression(cboHealth, ComboBox.SelectedIndexProperty);
        if (binding != null)
        {
          binding.UpdateTarget();
        }
        

        Also, make sure that HealthLevelID is public

        modified on Thursday, February 3, 2011 6:35 AM

        1 Reply Last reply
        0
        • P Pete OHanlon

          A couple of things here. 1. Your title needs some work. Simply stating wpf is not enough. 2. The code should be enclosed in pre tags. Now, your problem lies in the fact that SelectedIndex is actually zero based, so your values will not match. SelectedIndex should only be used to indicate the relative position of the object in your collection.

          I'm not a stalker, I just know things. Oh by the way, you're out of milk.

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Onyx

          A Offline
          A Offline
          arkiboys
          wrote on last edited by
          #4

          Hi, At present the HealthLevelID has only values 1 or 2 in it's tblHealthlevels table. Do you mean that since I am using selectedindex in xamml, I can change the integer values in the sql server table to be 0 and 1 instead of 1 and 2 and then it will work? If so, what if I add more values in the table such as 1, 2, 3, 4, ... Will my existing xaml work ok? Thanks

          1 Reply Last reply
          0
          • P Pete OHanlon

            A couple of things here. 1. Your title needs some work. Simply stating wpf is not enough. 2. The code should be enclosed in pre tags. Now, your problem lies in the fact that SelectedIndex is actually zero based, so your values will not match. SelectedIndex should only be used to indicate the relative position of the object in your collection.

            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            A Offline
            A Offline
            arkiboys
            wrote on last edited by
            #5

            I did do what you mentioned but still unable to solve this issue. Any thoughts please?

            P 1 Reply Last reply
            0
            • A arkiboys

              I did do what you mentioned but still unable to solve this issue. Any thoughts please?

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Rather than relying on the selected index, I prefer to use a selected item.

              I'm not a stalker, I just know things. Oh by the way, you're out of milk.

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Onyx

              A 1 Reply Last reply
              0
              • P Pete OHanlon

                Rather than relying on the selected index, I prefer to use a selected item.

                I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Onyx

                A Offline
                A Offline
                arkiboys
                wrote on last edited by
                #7

                Still have the same problem.

                1 Reply Last reply
                0
                • A arkiboys

                  I have populated a combo box as follows: <ComboBox Height="23" HorizontalAlignment="Left" Margin="120,6,0,0" Name="cboHealth" SelectedIndex="{Binding Path=HealthLevelID}" VerticalAlignment="Top" Width="256" /> private void PopulateHealthLevels() { List<clsDetails> healthlevels = new List<clsDetails>(); healthlevels = clsAccess.GetHealthLevels(); foreach (clsDetails details in healthlevels) { cboHealth.Items.Add(details.HealthLevelName); } } The datatable returns the HealthLevelID field as well as otherr fields. HealthLevelID has values of 1 and 2 for Normal and unNormal respectively. The combo box does get populated but it does not show the correct item for the selected row. What am I doing wrong please? Thanks

                  R Offline
                  R Offline
                  RichardGrimmer
                  wrote on last edited by
                  #8

                  You're missing Mode=TwoWay from your binding expression (assuming it's the same in WPF as Silverlight)

                  C# has already designed away most of the tedium of C++.

                  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