ListView problem
-
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
-
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
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-----
-
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-----
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 ... -
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 ...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 theComboBox
. Instead, just handle theComboBox.SelectedIndexChanged
. As far as the problem, if the above suggestion doesn't solve it (indirectly), make sure theComboBox
is throwing the event correctly and step through your code - as I said before - to find where the error is. Also, make sure that yourClearSelected
method isn't throwing any exceptions that would cause your code to exit prematurely before thelistView1.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-----