本文介绍了无法在ComboBox中将SelectedIndex设置为-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经缩小了一个问题我一直在填充一个组合框,其中 存储的查询结果数据表。我正在将ValueMember和 DisplayMember设置为相关的列名,然后我想确保 没有选择任何内容。 默认情况下,如果你什么也不做,那么第一项(0)就是 被选中。但是,我想将SelectedIndex设置为-1。 如果我有一个独立的窗口它可以工作,但如果我有一个窗口有一个 mdiparent set,它忽略了我将SelectedIndex设置为-1的尝试和 总是选择项目0. (这里是我的代码...... ) ComboBox1.DataSource = dt ComboBox1.ValueMember =" chCountryCode" ComboBox1.DisplayMember =" chCountryDesc" ComboBox1.SelectedIndex = -1 我已经尝试过两次设置SelectedIndex = -1,但这并没有解决 它。唯一似乎解决这个问题的是使窗口非childmdi, 但我们的应用程序是一个MDI风格的应用程序! 这是一个错误吗?请问有什么想法吗? 非常感谢, 史蒂夫Hi,I''ve narrowed down a problem I''ve been having filling a combobox with theresults of a query stored in a datatable. I''m setting the ValueMember andDisplayMember to the relevant column names, and then I want to make surenothing is selected.By default it appears that if you do nothing, the first item (0) isselected. However, I want to set the SelectedIndex to -1.If I have a standalone window it works, but if I have a window that has anmdiparent set, it ignores my attempts to set the SelectedIndex to -1 andalways selects item 0.(here''s my code...)ComboBox1.DataSource = dtComboBox1.ValueMember = "chCountryCode"ComboBox1.DisplayMember = "chCountryDesc"ComboBox1.SelectedIndex = -1I''ve already tried setting SelectedIndex = -1 twice, but that doesn''t fixit. The only thing that seems to fix it is making the window non-childmdi,but our application is an MDI style app!Is this a bug? Any ideas please?Many thanks,Steve推荐答案 BUG:ComboBox不将SelectedIndex设置为-1时清除 < URL:http://support.microsoft.com/?scid = kb; EN-US; 327244> - Herfried K. Wagner [MVP] < URL:http://dotnet.mvps.org/>BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>--Herfried K. Wagner [MVP]<URL:http://dotnet.mvps.org/> BUG:ComboBox不将SelectedIndex设置为-1时清除 < URL:http://support.microsoft.com/?scid = kb; EN-US; 327244> - Herfried K. Wagner [MVP] < URL:http://dotnet.mvps.org/>BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>--Herfried K. Wagner [MVP]<URL:http://dotnet.mvps.org/> BUG:ComboBox在您设置时不会清除SelectedIndex为-1 < URL:http://support.microsoft.com/?scid = kb; EN-US; 327244> - Herfried K. Wagner [MVP] < URL:http://dotnet.mvps.org/> BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1 <URL:http://support.microsoft.com/?scid=kb;EN-US;327244> -- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/> 这篇关于无法在ComboBox中将SelectedIndex设置为-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-26 04:51
查看更多