首页 新闻 会员 周边

C# .net开发:在datagridview的单元格中输入时内容始终是选中状态,导致只能输入一个字符

0
悬赏园豆:10 [已解决问题] 解决于 2014-08-04 14:18

例如:当单元格输入一串字符点击保存按钮,保存提示验证不通过,单元格内容处于选中状态,导致只能输入一个字符,单元格显示的是最后一个字符????

问题补充:

点击提示信息中的“确定”后,第三列的内容单元格只能输入一个字符了。

DerekFan的主页 DerekFan | 初学一级 | 园豆:16
提问于:2013-01-24 10:47
< >
分享
最佳答案
0

代码也贴出来看看吧

收获园豆:5
beio | 初学一级 |园豆:173 | 2013-01-28 16:03
View Code
 1          //格式列
 2             DataGridViewComboBoxColumn cboFormat = new DataGridViewComboBoxColumn();
 3             cboFormat.Name = "format";
 4             cboFormat.HeaderText = "格式";
 5             cboFormat.Width = 150;
 6             cboFormat.DataPropertyName = "Format";
 7             cboFormat.ValueMember = "Format";
 8             cboFormat.DisplayMember = "FormatName";
 9             DataTable dtFormat = new DataTable();
10             dtFormat.Columns.Add("Format", typeof(string));
11             dtFormat.Columns.Add("FormatName", typeof(string));
12             dtFormat.Rows.Add("1", "字段");
13             dtFormat.Rows.Add("2", "固定文本");
14             cboFormat.DataSource = dtFormat;
15             cboFormat.DefaultCellStyle.BackColor = Color.Gold;
16             cboFormat.DefaultCellStyle.NullValue = "字段";
17         
18             //内容列
19             DataGridViewTextBoxColumn txtContains = new DataGridViewTextBoxColumn();
20             txtContains.Name = "contains";
21             txtContains.HeaderText = "内容";
22             txtContains.Width = 150;
23             txtContains.DataPropertyName = "Contains";
24             txtContains.DefaultCellStyle.BackColor = Color.Gold;
25 /////////////////
26         for (int n = i+1; n < dgvMoudleInfos.Rows.Count-1; n++)
27                 {
28                     if (dgvMoudleInfos.Rows[n].Cells["format"].Value != null && dgvMoudleInfos.Rows[n].Cells["format"].Value.ToString()!="")
29                     {
30                         format2 = dgvMoudleInfos.Rows[n].Cells["format"].Value.ToString();
31                     }
32                     else
33                     {
34                         format2 = "1";
35                     }
36                     if (format == format2&& dgvMoudleInfos.Rows[i].Cells["contains"].Value.ToString() == dgvMoudleInfos.Rows[n].Cells["contains"].Value.ToString())
37                     {
38                         check = false;
39                     }
40                 }
41             }
42             if (check == false)
43             {
44                 MessageBox.Show("格式列和内容列不可以完全相同!");
45                 return;
46             }

datagridview 是通过数据库查询绑定的

存储过程:

View Code
 1 /****** Object:  StoredProcedure [dbo].[SearchFrom_InvRemarkCombineInfos]    Script Date: 01/24/2013 10:30:11 ******/
 2 IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchFrom_InvRemarkCombineInfos]') AND type in (N'P', N'PC'))
 3 DROP PROCEDURE [dbo].[SearchFrom_InvRemarkCombineInfos]
 4 GO
 5 
 6 
 7 
 8 /****** Object:  StoredProcedure [dbo].[SearchFrom_InvRemarkCombineInfos]    Script Date: 01/24/2013 10:30:11 ******/
 9 SET ANSI_NULLS ON
10 GO
11 
12 SET QUOTED_IDENTIFIER ON
13 GO
14 
15 
16 create proc [dbo].[SearchFrom_InvRemarkCombineInfos] 
17 @RCID int =null
18 as
19 begin 
20     select RIID,convert(varchar(30),Format) as Format,[Contains],JoinOpt,IsReadNull,convert(varchar(30),ReadType)as ReadType,CONVERT(varchar(30), Limits)as Limits,SeqNo from Inv_RemarkCombineInfos where RCID=@RCID order by SeqNo
21 end 
22 
23 GO
DerekFan | 园豆:16 (初学一级) | 2013-01-28 16:10

@MarkFun: dgvMoudleInfos这个是什么啊?

beio | 园豆:173 (初学一级) | 2013-01-28 16:20

@beio: winform 里面的DataGridview

DerekFan | 园豆:16 (初学一级) | 2013-01-29 17:44
其他回答(1)
0

截个图上来吧,你描述的不清楚。

收获园豆:5
jone_e | 园豆:1410 (小虾三级) | 2013-01-24 11:04

有截图了,帮我看看。谢谢

支持(0) 反对(0) DerekFan | 园豆:16 (初学一级) | 2013-01-24 13:22

@MarkFun: 这个问题很奇怪。。没有遇见过。。不好意思。。

支持(0) 反对(0) jone_e | 园豆:1410 (小虾三级) | 2013-01-25 12:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册