gpt4 book ai didi

c# - 如何让 DataGridView AutoComplete 只显示一列?

转载 作者:行者123 更新时间:2023-11-30 14:30:44 25 4
gpt4 key购买 nike

问题是 AutoComplete 还会显示第 1 列以外的列。它最初不会出现,直到我在第 1 列中输入文本,然后它才会开始显示其他列。

我的代码:

public AutoCompleteStringCollection ClientListDropDown()
{
AutoCompleteStringCollection asc = new AutoCompleteStringCollection();
try
{
Query = "Select top 5 title from customer "; // just removed where name like '%" + txtDVNo.Text + "%' plz check
cmd = new SqlCommand(Query, GlobalVars.conn);
dr = cmd.ExecuteReader();
if ((dr != null) && (dr.HasRows))
while (dr.Read())
asc.Add(dr.GetValue(0).ToString());
dr.Close();
cmd.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return asc;
}

private void dgvDVDetails_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dgvDVDetails.CurrentCell.ColumnIndex == 1)
{
TextBox prodCode = e.Control as TextBox;
if (prodCode != null)
{
prodCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
prodCode.AutoCompleteCustomSource = ClientListDropDown();
prodCode.AutoCompleteSource = AutoCompleteSource.CustomSource;

}
}
}

最佳答案

试试这个:

private void dgvDVDetails_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dgvDVDetails.CurrentCell.ColumnIndex == 1)
{
TextBox prodCode = e.Control as TextBox;
if (prodCode != null)
{
prodCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
prodCode.AutoCompleteCustomSource = ClientListDropDown();
prodCode.AutoCompleteSource = AutoCompleteSource.CustomSource;

}
}
else
{
TextBox prodCode = e.Control as TextBox;
if (prodCode != null)
{
prodCode.AutoCompleteMode = AutoCompleteMode.None;
}
}
}

关于c# - 如何让 DataGridView AutoComplete 只显示一列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com