C#中datagridview选中行后textbox显示选中的内容
我想让datagridview中某一行被选中时,textbox中显示选中的值,datagridview的选中模式是整行:
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
然后
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
int index = dataGridView1.CurrentRow.Index; //获取选中行的行号
textBox1.Text = dataGridView1.Rows[index].Cells[0].Value.ToString();
}
运行时选择datagridview里面的行没有问题,但是当我不小心点击到datagridview的列头时,就提示如下错误:
索引超出范围。必须为非负值并小于集合大小。
参数名: index
这个怎么办?正常情况下点击列头就应该是没有反应的
C#中datagridview选中行后textbox显示选中的内容
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (this.dataGridView1.SelectionMode != DataGridViewSelectionMode.FullColumnSelect)
{
int index = dataGridView1.CurrentRow.Index; //获取选中行的行号
textBox1.Text = dataGridView1.Rows[index].Cells[].Value.ToString();
};
}
C#中datagridview选中行后textbox显示选中的内容的更多相关文章
- C#——DataGridView选中行,在TextBox中显示选中行的内容
C#--DataGridView选中行,在TextBox中显示选中行的内容,在DataGridView的SelectionChanged实践中设置如下代码 private void dataGridV ...
- vue2.0 element-ui中的el-select选择器无法显示选中的内容
我使用的是element-ui V2.2.3.代码如下,当我选择值得时候,el-select选择器无法显示选中的内容,但是能触发change方法,并且能输出选择的值. select.vue文件 < ...
- 删除DataGridView选中行并更新数据库
前面写过一篇文章是DataGridView控件显示数据的,DataGridView在与数据库打交道时会常常出现,也非常有用.通过DataGridView对数据库进行更改和查询都比較方便. 这里我们须要 ...
- Ext.Net 使用总结之GridPanel中的选中行
1.判断GridPanel中是否选中了某行 if (!GridPanel1.hasSelection()) { Ext.Msg.alert("提示", "请选择记录!&q ...
- c# winform 中DataGridView绑定List<T> 不能显示数据
遇到问题 DataGridView绑定List后,List更新后再次绑定不显示数据 datagridview 绑定数据源的时候 用List是不能显示修改内容的..要用binginglist<T& ...
- 关于在elasticSearch中使用聚合查询后只显示10个bucket的问题
先看下面es查询语句 { "size": 0, "aggs" : { "all_articleId" : { "terms&quo ...
- DataGridView 选中行 分类: DataGridView 2015-01-22 09:07 51人阅读 评论(0) 收藏
说明: (1)命名 DataGridView 名称:dgvStockFirst 行索引:recordIndex (2)设置DataGridView属性: SelectionMode=FullRowSe ...
- Delphi DBGridEH中,选中行、列、单元格
// 新增行后,默认首列 procedure TForm1.ADOQuery1AfterInsert(DataSet: TDataSet);begin with DBGridEh1 do begi ...
- 获取table中CheckBox选中行的id
方式一 var selectList=''; jQuery(".table tbody input[type=checkbox]:checked").map(function () ...
随机推荐
- 02_Spark Application不同模式下的监控
监控Spark Application的运行 官方文档: http://spark.apache.org/docs/latest/monitoring.html 1.1 监控方式 Driver Pro ...
- WPF基础学习笔记整理 (八) 命令
基础知识: 命令是应用程序的任务,并跟踪任务是否能够被执行. 命令不包含执行应用程序任务的代码. 命令是比事件更高级的元素.默认的命令目标是当前获得焦点的元素. 良好的Win应用程序,应用程序逻辑不应 ...
- python 集合交补
setx = set(["apple", "mango"]) sety = set(["mango", "orange" ...
- pandas.read_csv参数整理
读取CSV(逗号分隔)文件到DataFrame,也支持文件的部分导入和选择迭代 更多帮助参见:http://pandas.pydata.org/pandas-docs/stable/io.html 参 ...
- 学以致用 ---- vue子组件→父组件通信
之前写过一篇关于 vue2.0中v-on绑定自定义事件 的随笔,但是今天实际应用的时候才发现根本就不理解,下面是实际工作中遇到的问题: [情景描述]页面中的[下拉搜索组件],因为多个页面中用到,所以抽 ...
- python2 安装scrapy出现错误提示解决办法~
首先:set STATICBUILD=true && pip install lxml 安装环境: windows7操作系统,已经正确安装python,pip. 使用pip功能安装Sc ...
- python - 面向对象编程(初级篇)
写了这么多python 代码,也常用的类和对象,这里准备系统的对python的面向对象编程做以下介绍. 面向对象编程(Object Oriented Programming,OOP,面向对象程序设计) ...
- TP5框架whereor
whereOr方法 Db::table('think_user') ->where('name','like','%thinkphp') ->whereOr('title','like', ...
- js插件---在线类似excel生成图表插件解决方案
js插件---在线类似excel生成图表插件解决方案 一.总结 一句话总结:google比百度好用多了,多用google google js editable table jquery 双向绑定 这种 ...
- javascript之构造函数的继承(引用网络)
这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例. 今天要介绍的是,对象之间的"继承"的五种方法. 比如,现在有一个" ...