【发布时间】:2026-02-11 08:10:01
【问题描述】:
我有一个从数据库绑定的组合框,现在我在组合框中写入文本时想要下拉列表,并从列表中选择与组合框中写入的文本匹配的数据。 组合框绑定成功,但在它的文本更改时,自动列表不是按照书面文本的下拉列表。请建议我如何做到这一点。 下面给出了我的绑定源
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mateenwin
{
public partial class Sale : Form
{
public Sale()
{
InitializeComponent();
PaymentType_bind();
Customer_bind();
}
/// combobox bind method
public void PaymentType_bind()
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=mateenwin;User ID=sa;Password=123");
SqlCommand command = new SqlCommand("Select * from PaymentType", con);
SqlDataAdapter adp = new SqlDataAdapter(command);
DataTable dt = new DataTable();
adp.Fill(dt);
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = "Payment_Type";
this.comboBox1.ValueMember = "Payment_Type_ID";
}
【问题讨论】:
标签: c# combobox windows-forms-designer