例如:当单元格输入一串字符点击保存按钮,保存提示验证不通过,单元格内容处于选中状态,导致只能输入一个字符,单元格显示的是最后一个字符????
点击提示信息中的“确定”后,第三列的内容单元格只能输入一个字符了。
代码也贴出来看看吧
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 是通过数据库查询绑定的
存储过程:
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
@MarkFun: dgvMoudleInfos这个是什么啊?
@beio: winform 里面的DataGridview
截个图上来吧,你描述的不清楚。
有截图了,帮我看看。谢谢
@MarkFun: 这个问题很奇怪。。没有遇见过。。不好意思。。