473,609 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating datagrid values

Hi

how do I validate a text value in a datagrid e.g. the user is only
allowed to type in a Y or a N. I specifically have a problem with
using the PropertyDescrip torCollection. I get the following error:
"Additional information: Cannot create a child list for field Query."
Below my existing code:

public class FrmQueryManagem ent : System.Windows. Forms.Form
{
private System.Windows. Forms.DataGrid dgMain;
private System.Windows. Forms.Button btnUpdate;
private System.Windows. Forms.Button btnClose;

// Declaring...
private SqlDataAdapter da;
private SqlCommandBuild er CmdBuilder;
private DataSet ds = new DataSet();
private System.Windows. Forms.GroupBox grpSelection;
private System.Windows. Forms.RadioButt on rbShowAll;
private System.Windows. Forms.RadioButt on rbStarted;
private System.Windows. Forms.RadioButt on rbEnded;
private System.Windows. Forms.RadioButt on rbNotAssigned;
//private System.Data.Sql Client.SqlConne ction SqlCn;

/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public FrmQueryManagem ent()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
DataGridCheckBo x();
GridBind();
//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.dgMain = new System.Windows. Forms.DataGrid( );
this.btnUpdate = new System.Windows. Forms.Button();
this.btnClose = new System.Windows. Forms.Button();
this.grpSelecti on = new System.Windows. Forms.GroupBox( );
this.rbNotAssig ned = new System.Windows. Forms.RadioButt on();
this.rbEnded = new System.Windows. Forms.RadioButt on();
this.rbStarted = new System.Windows. Forms.RadioButt on();
this.rbShowAll = new System.Windows. Forms.RadioButt on();
((System.Compon entModel.ISuppo rtInitialize)(t his.dgMain)).Be ginInit();
this.grpSelecti on.SuspendLayou t();
this.SuspendLay out();
//
// dgMain
//
this.dgMain.Cap tionText = "Query Management";
this.dgMain.Dat aMember = "";
this.dgMain.Hea derForeColor =
System.Drawing. SystemColors.Co ntrolText;
this.dgMain.Loc ation = new System.Drawing. Point(8, 80);
this.dgMain.Nam e = "dgMain";
this.dgMain.Siz e = new System.Drawing. Size(736, 216);
this.dgMain.Tab Index = 0;
this.dgMain.Mou seUp += new
System.Windows. Forms.MouseEven tHandler(this.d gMain_MouseUp);
this.dgMain.Nav igate += new
System.Windows. Forms.NavigateE ventHandler(thi s.dgMain_Naviga te);
//Initialise

private void GridBind()
{
String ConStr = MyGlobals.gsCon String;
SqlConnection myCon = new SqlConnection(C onStr);

try
{
myCon.Open();
}
catch (SqlException sqlex)
{
MessageBox.Show (sqlex.ToString ());
}

DataGridTableSt yle ts1 = new DataGridTableSt yle();
ts1.MappingName = "Query";
//Add the checkbox code here
DataGridColumnS tyle boolCol = new DataGridBoolCol umn();
boolCol.Mapping Name = "SelectStarted" ;
boolCol.HeaderT ext = "Start";
boolCol.Width = 30;
((DataGridBoolC olumn)boolCol). AllowNull = false;
ts1.GridColumnS tyles.Add(boolC ol);

DataGridColumnS tyle TextColStartDat e = new DataGridTextBox Column();
TextColStartDat e.MappingName = "StartDate" ; //from dataset table
TextColStartDat e.HeaderText = "Start Date";
TextColStartDat e.Width = 70;
TextColStartDat e.ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olStartDate);

DataGridColumnS tyle TextColStartUse r = new DataGridTextBox Column();
TextColStartUse r.MappingName = "StartUser" ; //from dataset table
TextColStartUse r.HeaderText = "Start User";
TextColStartUse r.Width = 60;
TextColStartUse r.ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olStartUser);

DataGridColumnS tyle boolColEnd = new DataGridBoolCol umn();
boolColEnd.Mapp ingName = "SelectEnde d";
boolColEnd.Head erText = "End";
boolColEnd.Widt h = 30;
((DataGridBoolC olumn)boolColEn d).AllowNull = false;
ts1.GridColumnS tyles.Add(boolC olEnd);

DataGridColumnS tyle TextColEndDate = new DataGridTextBox Column();
TextColEndDate. MappingName = "EndDate"; //from dataset table
TextColEndDate. HeaderText = "End Date";
TextColEndDate. Width = 70;
TextColEndDate. ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olEndDate);

DataGridColumnS tyle TextColEndUser = new DataGridTextBox Column();
TextColEndUser. MappingName = "EndUser"; //from dataset table
TextColEndUser. HeaderText = "End User";
TextColEndUser. Width = 60;
TextColEndUser. ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olEndUser);

DataGridColumnS tyle TextColFUDate = new DataGridTextBox Column();
TextColFUDate.M appingName = "Follow_Up_Date "; //from dataset table
TextColFUDate.H eaderText = "FU Date";
TextColFUDate.W idth = 70;
TextColFUDate.R eadOnly = true;
ts1.GridColumnS tyles.Add(TextC olFUDate);

PropertyDescrip torCollection pdc = this.BindingCon text[ds,
"Query"].GetItemPropert ies();
DataGridDigitsT extBoxColumn TextColResult = new
DataGridDigitsT extBoxColumn(pd c["Result_Comment "], "s", true);
//DataGridColumnS tyle TextColResult = new DataGridTextBox Column();
TextColResult.M appingName = "Result_Comment "; //from dataset table
TextColResult.H eaderText = "Result";
TextColResult.W idth = 50;
ts1.GridColumnS tyles.Add(TextC olResult);

DataGridColumnS tyle TextColFUStatus = new DataGridTextBox Column();
TextColFUStatus .MappingName = "Follow_up" ; //from dataset table
TextColFUStatus .HeaderText = "FU Status";
TextColFUStatus .Width = 70;
TextColFUStatus .ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olFUStatus);

DataGridColumnS tyle TextColContract Status = new
DataGridTextBox Column();
TextColContract Status.MappingN ame = "Contract_Statu s"; //from
dataset table
TextColContract Status.HeaderTe xt = "Contract Status";
TextColContract Status.Width = 70;
TextColContract Status.ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olContractStatu s);

DataGridColumnS tyle TextColEntitySt atus = new
DataGridTextBox Column();
TextColEntitySt atus.MappingNam e = "Entity_Status" ; //from dataset
table
TextColEntitySt atus.HeaderText = "Entity Status";
TextColEntitySt atus.Width = 70;
TextColEntitySt atus.ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olEntityStatus) ;

DataGridColumnS tyle TextColIDNo = new DataGridTextBox Column();
TextColIDNo.Map pingName = "Entity_Id_Numb er"; //from dataset table
TextColIDNo.Hea derText = "ID Number";
TextColIDNo.Wid th = 70;
TextColIDNo.Rea dOnly = true;
ts1.GridColumnS tyles.Add(TextC olIDNo);

DataGridColumnS tyle TextColContract No = new
DataGridTextBox Column();
TextColContract No.MappingName = "Contract_N o"; //from dataset table
TextColContract No.HeaderText = "Contract No";
TextColContract No.Width = 70;
TextColContract No.ReadOnly = true;
ts1.GridColumnS tyles.Add(TextC olContractNo);

DataGridColumnS tyle TextCol = new DataGridTextBox Column();
TextCol.Mapping Name = "Main_Name" ; //from dataset table
TextCol.HeaderT ext = "Main Name";
TextCol.Width = 100;
TextCol.ReadOnl y = true;
ts1.GridColumnS tyles.Add(TextC ol);

DataGridColumnS tyle TextCol2 = new DataGridTextBox Column();
TextCol2.Mappin gName = "First_Name "; //from dataset table
TextCol2.Header Text = "First Name";
TextCol2.Width = 100;
TextCol2.ReadOn ly = true;
ts1.GridColumnS tyles.Add(TextC ol2);

DataGridColumnS tyle csSeqNoInt = new DataGridTextBox Column();
csSeqNoInt.Mapp ingName = "SeqNo"; //from dataset table
csSeqNoInt.Head erText = "Seq No";
csSeqNoInt.Widt h = 20;
csSeqNoInt.Read Only = true;
ts1.GridColumnS tyles.Add(csSeq NoInt);
//Build the SQL statement for this user
string strWhere = " where Follow_Up in (";
SqlCommand cmdQry = new SqlCommand("sel ect * from
ctblrph_mo_quer y_management_se curity where UserName='" +
MyGlobals.gsUse rName + "'", myCon);
SqlDataReader dr;
dr = cmdQry.ExecuteR eader();
while (dr.Read())
{
strWhere = strWhere + "'" + dr.GetString(1) + "',";
}
strWhere = strWhere.Remove ((strWhere.Leng th-1),1);
strWhere = strWhere.Insert (strWhere.Lengt h,")");
dr.Close();
myCon.Close();
//MessageBox.Show (strWhere);

///instantiate SqlDataAdapter to create DataSet

//MessageBox.Show ("select * from ctblrph_mo_quer y_management " +
strWhere + " and (UserBeing='" + MyGlobals.gsUse rName + "' or
UserBeing = ''");
da = new SqlDataAdapter( "select * from ctblrph_mo_quer y_management
" + strWhere + " and (StartUser='" + MyGlobals.gsUse rName + "' or
StartUser is null)",myCon);
/*seqno, main_name,first _name, contract_no*/
/// the following is for creating automatic command builder
CmdBuilder = new SqlCommandBuild er(da);

///fill the dataset
try
{
da.Fill(ds, "Query");
}
catch (SqlException sqlex)
{
MessageBox.Show (sqlex.ToString ());
}

///set the dataset as a datasource for windows datagrid
dgMain.SetDataB inding(ds,"Quer y");
dgMain.TableSty les.Add(ts1);
}

private void dgMain_Navigate (object sender,
System.Windows. Forms.NavigateE ventArgs ne)
{

}

private void dgMain_MouseUp( object sender,
System.Windows. Forms.MouseEven tArgs e)
{
// Use the DataGrid control's HitTest method with the x and y
properties.
if(dgMain.HitTe st(e.X,e.Y).Col umn == 0)
{
dgMain[dgMain.CurrentC ell.RowNumber, 2] = MyGlobals.gsUse rName;
dgMain[dgMain.CurrentC ell.RowNumber, 1] = DateTime.Today;
}
if(dgMain.HitTe st(e.X,e.Y).Col umn == 3)
{
dgMain[dgMain.CurrentC ell.RowNumber, 5] = MyGlobals.gsUse rName;
dgMain[dgMain.CurrentC ell.RowNumber, 4] = DateTime.Today;
}
if(dgMain.HitTe st(e.X,e.Y).Col umn == 7) //Result
{
/*
if(dgMain[dgMain.CurrentC ell.RowNumber, 7] == "Y" ||
dgMain[dgMain.CurrentC ell.RowNumber, 7] == "N")
{
}
else
{
MessageBox.Show ("Invalid Result. Can only be Y or N!");
dgMain[dgMain.CurrentC ell.RowNumber, 7] = "";
}
*/
}
}
}
public class DataGridDigitsT extBoxColumn : DataGridTextBox Column
{
public DataGridDigitsT extBoxColumn(Sy stem.ComponentM odel.PropertyDe scriptor
pd, string format, bool b)
: base(pd, format, b)
{
this.TextBox.Ke yPress += new
System.Windows. Forms.KeyPressE ventHandler(Han dleKeyPress);

}

private void HandleKeyPress( object sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
//ignore if not digit or control key
if(!char.IsDigi t(e.KeyChar) && !char.IsControl (e.KeyChar))
e.Handled = true;

//ignore if more than 3 digits
if(this.TextBox .Text.Length >= 3 && !char.IsControl (e.KeyChar) &&
this.TextBox.Se lectionLength == 0)
e.Handled = true;
}

protected override void Dispose(bool disposing)
{
if(disposing)
this.TextBox.Ke yPress -= new
System.Windows. Forms.KeyPressE ventHandler(Han dleKeyPress);

base.Dispose(di sposing);

}
}
}
Nov 15 '05 #1
0 3187

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1541
by: Omavlana | last post by:
Pleas advise me how to do validations in side datagrid before updating the details into database. I am using VB.NET and updating the datagrid using sqlcommandbuilder. I want to validate the data that user changhes inside the grid. How can I do this? Pls help...
0
2685
by: Morné | last post by:
Hi how do I validate a text value in a datagrid e.g. the user is only allowed to type in a Y or a N. I specifically have a problem with using the PropertyDescriptorCollection. I get the following error: "Additional information: Cannot create a child list for field Query." Below my existing code:
0
1147
by: enahar | last post by:
I want to validate a cell wheather a value is greater than 0 or not.If value is greater than 0 then I want to show messagebox and focus back the same cell else move to the other cell. I am writing the following code on the column_chnaging and tetbox validating events, but nothing works .If value is greater than 0 then it pops up the message but focus moves to the other cell.
0
1331
by: SMai24 | last post by:
Anyone has the same experience? I am trying to validate one of the textboxes inside a datagrid, but everytime when i click my mouse on another cell, the validating fires twice. Help plz....
0
1464
by: Ante Perkovic | last post by:
Hi, After long search of the internet, I couldn't find any solution on validating a datagrid. I have textboxes and validators (required field) in <editItemTemplate> and labels in <ItemTemplate>. My validators can't find textboxes! Why? Please help!
3
1055
by: Devlei | last post by:
I have a column in a datagrid that I want to limit the values to integers from 1 to 5. What is the best way to do this? The datagrid is bound to a typed dataset that is populated from an XML file. With thanks Dave
3
2793
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
9
2713
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
2
1537
by: Jason Huang | last post by:
Hi, In my .Net C# Windows form Form1, there's a DataGrid DataGrid1 on Form1. How do I validate if the values in DataGrid1 is modified or not? Thanks for help. Jason
0
8095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8556
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8410
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6068
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4037
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2541
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1690
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.