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. ListView problem

ListView problem

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

    hi i have just added this auto complete feature in my combo box .. When the user leaves the focus from the combobox .. it fires the leave event ... in this event i do this ... listView.Items[index].Selected = true; And in the list view selected event i have added some code that get the data from the listview and put them into the appropraite textBoxs or Combox... my problem is this code works just fine only 1 time... the second time it does execute the leave focus event but dosnt set the selected index ... i have no idea why is it doing that Thanks DaIn

    H 1 Reply Last reply
    0
    • D datainjector

      hi i have just added this auto complete feature in my combo box .. When the user leaves the focus from the combobox .. it fires the leave event ... in this event i do this ... listView.Items[index].Selected = true; And in the list view selected event i have added some code that get the data from the listview and put them into the appropraite textBoxs or Combox... my problem is this code works just fine only 1 time... the second time it does execute the leave focus event but dosnt set the selected index ... i have no idea why is it doing that Thanks DaIn

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Did you try debugging and stepping through the relevent code line by line? Sometimes unexpected exceptions are thrown and handled, or a condition fails. In either case, you should be able to find more information that may help you solve the problem, or provide some additional information to post along with your problem; because, by itself this post doesn't really present any particular problems.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      D 1 Reply Last reply
      0
      • H Heath Stewart

        Did you try debugging and stepping through the relevent code line by line? Sometimes unexpected exceptions are thrown and handled, or a condition fails. In either case, you should be able to find more information that may help you solve the problem, or provide some additional information to post along with your problem; because, by itself this post doesn't really present any particular problems.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        D Offline
        D Offline
        datainjector
        wrote on last edited by
        #3

        private void listView1_SelectedIndexChanged(object sender, System.EventArgs e) { if ( listView1.SelectedItems.Count > 0 ) { codeComboBox.Text = listView1.SelectedItems[0].SubItems[0].Text; modNameTextBox.Text = listView1.SelectedItems[0].SubItems[2].Text; modAdd1TextBox.Text = listView1.SelectedItems[0].SubItems[3].Text; modAdd2TextBox.Text = listView1.SelectedItems[0].SubItems[4].Text; modCityTextBox.Text = listView1.SelectedItems[0].SubItems[5].Text; modPinTextBox.Text = listView1.SelectedItems[0].SubItems[6].Text; modPhoneTextBox.Text = listView1.SelectedItems[0].SubItems[7].Text; modContactPersonTextBox.Text = listView1.SelectedItems[0].SubItems[1].Text; } } Thats for the selected index.... private void codeComboBox_Leave(object sender, System.EventArgs e) { ClearSelected(); listView1.Items[index].Selected = true; } The index Varaible stores the index of the ID in the listView... This only seams to execute once ...

        H 1 Reply Last reply
        0
        • D datainjector

          private void listView1_SelectedIndexChanged(object sender, System.EventArgs e) { if ( listView1.SelectedItems.Count > 0 ) { codeComboBox.Text = listView1.SelectedItems[0].SubItems[0].Text; modNameTextBox.Text = listView1.SelectedItems[0].SubItems[2].Text; modAdd1TextBox.Text = listView1.SelectedItems[0].SubItems[3].Text; modAdd2TextBox.Text = listView1.SelectedItems[0].SubItems[4].Text; modCityTextBox.Text = listView1.SelectedItems[0].SubItems[5].Text; modPinTextBox.Text = listView1.SelectedItems[0].SubItems[6].Text; modPhoneTextBox.Text = listView1.SelectedItems[0].SubItems[7].Text; modContactPersonTextBox.Text = listView1.SelectedItems[0].SubItems[1].Text; } } Thats for the selected index.... private void codeComboBox_Leave(object sender, System.EventArgs e) { ClearSelected(); listView1.Items[index].Selected = true; } The index Varaible stores the index of the ID in the listView... This only seams to execute once ...

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          The ComboBox.Leave event is probably not the place you want to be doing this. This event occurs every time your mouse exits the region filled by the ComboBox. Instead, just handle the ComboBox.SelectedIndexChanged. As far as the problem, if the above suggestion doesn't solve it (indirectly), make sure the ComboBox is throwing the event correctly and step through your code - as I said before - to find where the error is. Also, make sure that your ClearSelected method isn't throwing any exceptions that would cause your code to exit prematurely before the listView1.Items[index].Selected = true is executed.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          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