在Winform中的组合框中显示项目 [英] Displaying item in combobox in winform

查看:59
本文介绍了在Winform中的组合框中显示项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在Windows应用程序上工作.在应用程序中,我有一个组合框和一个按钮.当我单击添加"按钮时,将显示一个窗口,并且在该窗口中正在文本框中添加项目,然后单击保存",它应保存在数据库中并关闭该窗口.我使用set datasource属性在组合框中显示项目.实际上,我需要添加的项目应该在关闭弹出窗口后的组合框中选择.

Hi All,

Am working on windows application .In the application I have one combo box and one button. When i click on the Add button One window will be displaying And In that window am adding items in textbox and click on save its should be saving in the database and closing the window. Am displaying the items in combobox using set datasource property. Actually i need just now i added item should select in the combo box after the closing pop up window.

推荐答案

Try
Try
comboBox1.Items.Add("item");<br />
comboBox1.SelectedIndex = comboBox1.Items.Count;<br />


您可以在查询中使用ORDER BY子句.以下代码段可能会对您有所帮助

You can use ORDER BY clause in your query. Following code snippet might help you

SELECT item_id, item_name FROM yourTableName ORDER BY item_id DESC


此查询将按降序对项目进行排序,之后,您可以将通过此查询检索到的项目绑定到ComboBox.

您可以在关闭第二种表单后绑定数据...

希望这对您有帮助...


This query will sort your item in descending order, after that you can bind retrieved item through this query to your ComboBox.

You can bind your data after closing the second form...

Hope this will help you...


这篇关于在Winform中的组合框中显示项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆