資源簡介
Q703119 問題的回答 c# combobox如何動態模糊查詢? https://ask.csdn.net/questions/703119 v2,修正了幾個問題,初始化不加載

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Data.SqlClient;
namespace?Q703119
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????????//loadcombo();
????????}
????????bool?inloading?=?false;
????????private?void?loadcombo()
????????{
????????????if?(comboBox1.Items.Count?==?0?&&?comboBox1.Text?==?““)?return;
????????????if?(comboBox1.Text?==?““)?{?comboBox1.DroppedDown?=?false;?comboBox1.Items.Clear();?return;?}
????????????if?(inloading)?return;
????????????string?s?=?comboBox1.Text;
????????????int?n?=?comboBox1.Selectionstart;
????????????string?conntext?=?@“Data?Source=.\sqlexpress;Initial?Catalog=Q703119DB;Integrated?Security=True;Pooling=False“;
????????????SqlConnection?conn?=?new?SqlConnection(conntext);
????????????string?sql?=?“select?*?from?Book?where?BookName?like?‘%“?+?comboBox1.Text?+?“%‘“;
????????????SqlDataAdapter?adp?=?new?SqlDataAdapter(sql?conn);
????????????DataSet?ds?=?new?DataSet();
????????????adp.Fill(ds);
????????????comboBox1.Items.Clear();
????????????foreach?(DataRow?item?in?ds.Tables[0].Rows)
????????????????comboBox1.Items.Add(item[“bookname“].ToString().Trim());
????????????inloading?=?true;
????????????comboBox1.Text?=?s;
????????????Application.DoEvents();
????????????//if?(comboBox1.Text.Length?>=?n)
????????????????comboBox1.Selectionstart?=?n;
????????????inloading?=?false;
????????}
????????private?void?comboBox1_TextChanged(object?sender?EventArgs?e)
????????{
????????????loadcombo();
????????}
????????private?void?comboBox1_KeyDown(object?sender?KeyEventArgs?e)
????????{
????????????comboBox1.DroppedDown?=?true;
????????}
????????private?void?comboBox1_Leave(object?sender?EventArgs?e)
????????{
????????????comboBox1.DroppedDown?=?false;
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????9728??2018-10-22?12:01??Q703119\bin\Debug\Q703119.exe
?????文件??????26112??2018-10-22?12:01??Q703119\bin\Debug\Q703119.pdb
?????文件??????11600??2018-10-22?12:03??Q703119\bin\Debug\Q703119.vshost.exe
?????文件????????490??2010-03-17?22:39??Q703119\bin\Debug\Q703119.vshost.exe.manifest
?????文件???????2027??2018-10-22?12:01??Q703119\Form1.cs
?????文件???????2214??2018-10-19?10:45??Q703119\Form1.Designer.cs
?????文件???????5817??2018-10-19?10:45??Q703119\Form1.resx
?????文件???????2152??2018-10-22?11:46??Q703119\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6356??2018-10-22?12:01??Q703119\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????428??2018-10-22?11:48??Q703119\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件????????954??2018-10-22?11:48??Q703119\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件???????1831??2018-10-22?12:03??Q703119\obj\x86\Debug\Q703119.csproj.FileListAbsolute.txt
?????文件????????975??2018-10-19?10:45??Q703119\obj\x86\Debug\Q703119.csproj.GenerateResource.Cache
?????文件???????9728??2018-10-22?12:01??Q703119\obj\x86\Debug\Q703119.exe
?????文件????????180??2018-10-22?11:48??Q703119\obj\x86\Debug\Q703119.Form1.resources
?????文件??????26112??2018-10-22?12:01??Q703119\obj\x86\Debug\Q703119.pdb
?????文件????????180??2018-10-22?11:48??Q703119\obj\x86\Debug\Q703119.Properties.Resources.resources
?????文件????????499??2018-10-19?10:09??Q703119\Program.cs
?????文件???????1426??2018-10-19?10:09??Q703119\Properties\AssemblyInfo.cs
?????文件???????2844??2018-10-19?10:09??Q703119\Properties\Resources.Designer.cs
?????文件???????5612??2018-10-19?10:09??Q703119\Properties\Resources.resx
?????文件???????1094??2018-10-19?10:09??Q703119\Properties\Settings.Designer.cs
?????文件????????249??2018-10-19?10:09??Q703119\Properties\Settings.settings
?????文件???????3673??2018-10-19?10:18??Q703119\Q703119.csproj
?????文件????????863??2018-10-19?10:09??Q703119.sln
????..A..H.?????22528??2018-10-22?12:03??Q703119.suo
?????目錄??????????0??2018-10-19?10:09??Q703119\obj\x86\Debug\TempPE
?????目錄??????????0??2018-10-22?12:01??Q703119\obj\x86\Debug
?????目錄??????????0??2018-10-19?10:18??Q703119\bin\Debug
?????目錄??????????0??2018-10-19?10:09??Q703119\obj\x86
............此處省略7個文件信息
評論
共有 條評論