在 ComboBox 中加载数据时应选择第一个值
我有一个组合框并从服务器动态加载数据。我需要将组合框中的第一个值显示为选定值,并根据该值将数据填充到网格上。如果有人知道,请给我发送一个相同的示例。
谢谢, 拉维
I had a comboBox and loading the datadynamically from the server. i need to display the first value in comboBox as a selected value and based on the value data should be populated on the grid. Please send me a sample example on the same if nay one knows.
thanks,
Ravi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过设置:
selectedIndex=0
或设置selectedItem
属性来选择第一个值。但您应该确保有一个项目可供您选择。例如,这可以在 dataProvider 的 setter 中完成。
You can select the first value by setting:
selectedIndex=0
or set theselectedItem
property.But you should make sure that there is an item which you can select. This could be for example done in the setter of the dataProvider.
确保您拥有数据的另一种方法是向 dataProvider 添加 ChangeWatcher,以便在绑定新数据时通知您。然后你可以简单地遍历数据并选择你想要的任何一个,在你的情况下 selectedIndex=0;
Another way to make sure that you have data is add a ChangeWatcher to the dataProvider, so that you will be notified when new data is bound. Then you can simply traverse the data and select whichever one you want, in your case selectedIndex=0;