A listview inside a combo box
-
Hi Experts, I am not sure if i would be able to explain my problem efficiently or not but yeah will definitely try. I have a user control which contains a combo box. I have added a listview inside the combo box as
cboComboBoxControl.Items.Add(lstvMyView);
. I have also handled the selection changed event of the list view so that when the selection gets changed the text area of the combo box gets populated with one of the column given in the list view. I have done this asvoid lstvMyView\_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataRowView drv = (DataRowView)lstvMyView.SelectedValue; cboComboBoxControl.Text = drv.Row\["TextCol"\].ToString(); }
Now when i run the code and keep my mouse clicked (left mouse button is down and is not yet released) on a row in the listview the text gets changed to the desired value but as soon as i leave my left mouse button the value in the text gets changed to "System.Windows.Controls.ListView Items.Count:2" i.e. it shows me the number of rows in the listview. Anyone please help! Thanks in advance! Regards, Samar
-
Hi Experts, I am not sure if i would be able to explain my problem efficiently or not but yeah will definitely try. I have a user control which contains a combo box. I have added a listview inside the combo box as
cboComboBoxControl.Items.Add(lstvMyView);
. I have also handled the selection changed event of the list view so that when the selection gets changed the text area of the combo box gets populated with one of the column given in the list view. I have done this asvoid lstvMyView\_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataRowView drv = (DataRowView)lstvMyView.SelectedValue; cboComboBoxControl.Text = drv.Row\["TextCol"\].ToString(); }
Now when i run the code and keep my mouse clicked (left mouse button is down and is not yet released) on a row in the listview the text gets changed to the desired value but as soon as i leave my left mouse button the value in the text gets changed to "System.Windows.Controls.ListView Items.Count:2" i.e. it shows me the number of rows in the listview. Anyone please help! Thanks in advance! Regards, Samar
Hi Experts any thoughts on this..??? Please do let me know if you need any other input from my side. Regards, Samar
-
Hi Experts, I am not sure if i would be able to explain my problem efficiently or not but yeah will definitely try. I have a user control which contains a combo box. I have added a listview inside the combo box as
cboComboBoxControl.Items.Add(lstvMyView);
. I have also handled the selection changed event of the list view so that when the selection gets changed the text area of the combo box gets populated with one of the column given in the list view. I have done this asvoid lstvMyView\_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataRowView drv = (DataRowView)lstvMyView.SelectedValue; cboComboBoxControl.Text = drv.Row\["TextCol"\].ToString(); }
Now when i run the code and keep my mouse clicked (left mouse button is down and is not yet released) on a row in the listview the text gets changed to the desired value but as soon as i leave my left mouse button the value in the text gets changed to "System.Windows.Controls.ListView Items.Count:2" i.e. it shows me the number of rows in the listview. Anyone please help! Thanks in advance! Regards, Samar
Hi Experts I got the solution for this. I added the MouseLeftButtonUp Event and added the following code.
void lstvMyView\_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { e.Handled = true; }
Because of this the drop down would not close when the selection in the listview gets changed. So I added "IsDropDownOpen" = false on selection changed event of listview as
void lstvMyView\_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataRowView drv = (DataRowView)lstvMyView.SelectedValue; cboComboBoxControl.Text = drv.Row\["TextCol"\].ToString(); cboComboBoxControl.IsDropDownOpen = false; }
I guess everyone knew i would finally get it!!! Isnt it??? :laugh: Thanks anyways!! Regards, Samar