在DataGridView单元格中,当输入指定字符时,自动完成填充。

通过 TextBox实现

AutoCompleteMode

AutoCompleteMode.Suggest;

AutoCompleteSource

AutoCompleteSource.customSource;

namespace DataGridView单元格自动填充
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
string constr = "server=192.168.100.222;user=sa;pwd=p@ssw1rd;database=pwd1";
SqlConnection mycon = new SqlConnection(constr); try
{
mycon.Open();
DataTable mytb = new DataTable();
SqlDataAdapter mydpt = new SqlDataAdapter("select * from book",mycon);
mydpt.Fill(mytb);
dataGridView1.DataSource = mytb;
mycon.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message);
} }
//添加编辑控件显示事件
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
//定义字符串来确定你要自动填充那列
string titletext=dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText; //判断title和“shuoming”是否相等也可以用等号==
if (titletext.Equals("shuoming"))
{
//控件textbox = 编辑控件显示事件 别名为textbox
TextBox autotext = e.Control as TextBox;
if (autotext!=null)
{
autotext.AutoCompleteMode = AutoCompleteMode.Suggest;
autotext.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection datacoll = new AutoCompleteStringCollection();
datacoll.Add("监控专用");
datacoll.Add("共享专用");
autotext.AutoCompleteCustomSource= datacoll; } }

DataGridView 单元格自动填充的更多相关文章

  1. excel如何设置输入数字后单元格自动填充颜色

    在使用excel的过程中,有时需要在输入数字时,突出显示这些单元格,突出显示可以用有填充颜色的单元格来表示.为了实现这样的效果,需要借助excel的条件格式. 工具/原料 电脑 Excel 2010 ...

  2. 【Winform-自定义控件】DataGridView 单元格合并和二维表头

    DataGridView单元格合并和二维表头应用: //DataGridView绑定数据 DataTable dt = new DataTable(); dt.Columns.Add("); ...

  3. winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难

    // winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...

  4. DataGridView单元格合并

    本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...

  5. DataGridView单元格显示GIF图片

    本文转载:http://home.cnblogs.com/group/topic/40730.html DataGridView单元格显示GIF图片 gifanimationindatagrid.ra ...

  6. Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)

    设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);

  7. Winform Datagridview 单元格html格式化支持富文本

    Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...

  8. 设置DataGridView单元格的文本对齐方式

    实现效果: 知识运用: DataGridViewCellStyle类的Alignment属性     //获取或设置DataGridView单元格内的单元格内容的位置 public DataGridV ...

  9. WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序

    TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...

随机推荐

  1. 比较有用的php代码片段

    一 从网页中提取关键词 $meta = get_meta_tags('http://www.emoticode.net/'); $keywords = $meta['keywords']; // Sp ...

  2. Java多线程原理及Thread类的使用

    一.进程与线程的区别 1.进程是应用程序在内存总分配的空间.(正在运行中的程序) 2.线程是进程中负责程序执行的执行单元.执行路径. 3.一个进程中至少有一个线程在负责进程的运行. 4.一个进程中有多 ...

  3. 在myeclipse中有的项目上有个红色感叹号

    之前做项目的时候遇到过这个问题,最后确定原因是项目引用了很多放在D盘或E盘上的jar包,但是我们不小心把这些jar包删除或移动路径了,因此myeclipse识别不了出现红色的感叹号,解决方式是在mye ...

  4. S2-052复现过程(附POC利用)

    漏洞编号:CVE-2017-9805(S2-052) 影响版本:Struts 2.5 - Struts 2.5.12 漏洞概述:问题出现在struts2-rest-plugin插件XStreamHan ...

  5. shell实战之case语句的选择提示

    知识点包括:case语句,cat多行输入,break和exit的区别,wget断点续传,while中断条件写法,函数的使用方法 #!/bin/bash echo "\n1. 本机容器情况如下 ...

  6. 【JavaScript】类继承(对象冒充)和原型继承__深入理解原型和原型链

    JavaScript里的继承方式在很多书上分了很多类型和实现方式,大体上就是两种:类继承(对象冒充)和原型继承. 类继承(对象冒充):在函数内部定义自身的属性的方法,子类继承时,用call或apply ...

  7. SQL Server——存储过程(Stored Procedure)、事物、触发器

    存储过程(proc 或 procedure) 存储过程(Stored Procedure),计算机用语,是一组为了完成特定功能的SQL语句集,是利用SQL Server所提供的Transact-SQL ...

  8. Junit 测试exception

    有两种方法: 一.使用ExpectedException 仅在junit4.7以上支持.不仅可以测试捕获到某异常,也可以测试异常message. 使用例子如下: @Rule public Expect ...

  9. day2: python3.5学习——逻辑判断

    1. 简单的用户名和密码输入 username = "Helen"password = "123abc" _username = input("use ...

  10. 判断IE浏览器的版本号

    function IEVersion() { var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE = userAgen ...