在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. [uwp]数据绑定再学习

    在开始上代码前,先来假设这样一种情形: 出于某些原因,创建一个自定义控件(UserControl),然后为它定义一个依赖属性,这个属性有两个作用,一是调用控件方通过数据绑定技术为它赋值,二是控件内部的 ...

  2. XHTML与HTML、HTML5的区别

    XHTML与HTML最主要的区别 XHTML 元素必须被正确地嵌套. XHTML 元素必须被关闭. XHTML标签名必须用小写字母. XHTML 文档必须拥有根元素. HTML5 HTML5是很有野心 ...

  3. 【OCP-12c】2019年CUUG OCP 071考试题库(79题)

    79.Which statement is true about transactions? A. A set of Data Manipulation Language (DML) statemen ...

  4. BZOJ 1922--大陆争霸(最短路)

    1922: [Sdoi2010]大陆争霸 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 2113  Solved: 947[Submit][Status ...

  5. python学习笔记-控制流(if for while break continue)

    if语句 if语句用以检查条件:如果条件为真(True),将运行一块语句(称作 if-block 或 if 块),否则将运行另一块语句(称作 else-block 或 else 块).其中else 从 ...

  6. “ping”简单报错理解

    了解ABC类IP地址:网络.主机.子网.广播. ———————————————————————————- 学会ping: ping www.itxdm.me 网络检测:ping某一主机可以正常启动!( ...

  7. python接口自动化2-发送post请求详解(二)

    前言 发送post的请求参考例子很简单,实际遇到的情况却是很复杂的,首先第一个post请求肯定是登录了,但登录是最难处理的.登录问题解决了,后面都简单了. 一.查看官方文档 1.学习一个新的模块,其实 ...

  8. Dubbo自定义日志拦截器

    前言 上一篇文章 Spring aop+自定义注解统一记录用户行为日志 记录了 web层中通过自定义注解配合Spring aop自动记录用户行为日志的过程.那么按照分布式架构中Dubbo服务层的调用过 ...

  9. day 09 课后作业

    # -*- coding: utf-8 -*-# @Time : 2018/12/28 14:25# @Author : Endless-cloud# @Site : # @File : 08 课后作 ...

  10. docker 暴露2375 端口。

    网上找的.大多不能用...一下是我自己找了半天的方法...,可能是版本太旧的原因 下图解决方法: ubuntu: 18.04 docker: Docker version 18.09.2, build ...