DataGridView 单元格自动填充
在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 单元格自动填充的更多相关文章
- excel如何设置输入数字后单元格自动填充颜色
在使用excel的过程中,有时需要在输入数字时,突出显示这些单元格,突出显示可以用有填充颜色的单元格来表示.为了实现这样的效果,需要借助excel的条件格式. 工具/原料 电脑 Excel 2010 ...
- 【Winform-自定义控件】DataGridView 单元格合并和二维表头
DataGridView单元格合并和二维表头应用: //DataGridView绑定数据 DataTable dt = new DataTable(); dt.Columns.Add("); ...
- winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难
// winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...
- DataGridView单元格合并
本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...
- DataGridView单元格显示GIF图片
本文转载:http://home.cnblogs.com/group/topic/40730.html DataGridView单元格显示GIF图片 gifanimationindatagrid.ra ...
- Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)
设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);
- Winform Datagridview 单元格html格式化支持富文本
Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...
- 设置DataGridView单元格的文本对齐方式
实现效果: 知识运用: DataGridViewCellStyle类的Alignment属性 //获取或设置DataGridView单元格内的单元格内容的位置 public DataGridV ...
- WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序
TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...
随机推荐
- Modular Arithmetic ( Arithmetic and Algebra) CGAL 4.13 -User Manual
1 Introduction Modular arithmetic is a fundamental tool in modern algebra systems. In conjunction wi ...
- ClamAV学习【5】—— cli_scanpe函数浏览
这近2000行的代码,要是没有Source Insight,都不知道怎么看下去.跟着跟着来到了PE文件查杀的地方,发现前面都中规中矩地进行PE属性检查,中间一段开始扫描每个区块,然后和特征库的size ...
- 【12c OCP】最新CUUG OCP-071考试题库(52题)
52.(12-11) choose the best answer: Examine the structure and data in the PRICE_LIST table: You plan ...
- iOS水波纹效果
最近也是在学习一些动画效果的实现,也找了一些Demo进行练习,先放出原地址http://www.cocoachina.com/ios/20161104/17960.html,感谢大神的分享,作者对实现 ...
- IIS7的网站通过https访问提示ssl_error_rx_record_too_long
IIS7的网站通过https访问,提示ssl_error_rx_record_too_long,如下图所示: 解决办法: 一.导入服务器的SSL证书至IIS 1.打开IIS,找到服务器证书 2.导入本 ...
- 洛谷P3964 [TJOI2013]松鼠聚会(坐标系变换)
题面 传送门 题解 对于两个点\((x_i,y_i)\)和\(x_j,y_j\),我们定义它们之间的曼哈顿距离为 \[|x_i-x_j|+|y_i-y_j|\] 定义它们的切比雪夫距离为 \[\max ...
- robot framework学习笔记之九-杂记
Setup和Teardown 假设Suite1下面有Test1和Test2,若它们都设置了Setup和Teardown,那么它们的执行顺序是:Suite1-Setup->Test1-Setup- ...
- django参考博客学习
网上发现其他人的一个django系列博客,和我学的一样是黑马的,写的挺不错的,转载学习一下 https://blog.csdn.net/u014745194/article/category/6989 ...
- SQL面试题(网络收集)
1. 用一条SQL 语句 查询出每门课都大于80 分的学生姓名 name kecheng fenshu 张三 语文 81 张三 数学 75 李四 ...
- Objective-C Associated Objects 的实现原理
我们知道,在 Objective-C 中可以通过 Category 给一个现有的类添加属性,但是却不能添加实例变量,这似乎成为了 Objective-C 的一个明显短板.然而值得庆幸的是,我们可以通过 ...