{"id":80,"date":"2009-10-25T20:20:13","date_gmt":"2009-10-25T19:20:13","guid":{"rendered":"http:\/\/blog.rabihtawil.com\/?p=70"},"modified":"2009-10-25T20:20:13","modified_gmt":"2009-10-25T19:20:13","slug":"validate-data-entered-into-textboxcolumn","status":"publish","type":"post","link":"http:\/\/www.raytawil.com\/?p=80","title":{"rendered":"Validate data entered into textboxcolumn"},"content":{"rendered":"<blockquote><p><span id=\"ctl00_ContentPlaceHolder1_ListView1_ctrl0_Label1\">To validate the text entered into a datagrid add a handler to the DatagridTextboxColumn&#8217;s validating event. Here is some sample code.<\/span><\/p>\n<p><span style=\"color: #000080;\"> Dim ds As New DataSet<\/span><\/p>\n<p>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br \/>\nDim conn As SqlConnection<br \/>\nDim strConn As String<br \/>\nDim strSQL As String<br \/>\nDim da As SqlDataAdapter<\/p>\n<p>strConn = &#8220;Server = (local);&#8221;<br \/>\nstrConn &amp;= &#8220;Database = NorthWind;&#8221;<br \/>\nstrConn &amp;= &#8220;Integrated Security = SSPI;&#8221;<\/p>\n<p>conn = New SqlConnection(strConn)<br \/>\nda = New SqlDataAdapter(&#8220;Select * From Products&#8221;, conn)<br \/>\nda.Fill(ds, &#8220;Products&#8221;)<\/p>\n<p>Dim ts As New DataGridTableStyle<br \/>\nts.MappingName = ds.Tables(&#8220;Products&#8221;).TableName<\/p>\n<p>Dim colDiscontinued As New DataGridBoolColumn<br \/>\nWith colDiscontinued<br \/>\n.MappingName = &#8220;Discontinued&#8221;<br \/>\n.HeaderText = &#8220;Discontinued&#8221;<br \/>\n.Width = 80<br \/>\nEnd With<\/p>\n<p>Dim colName As New DataGridTextBoxColumn<br \/>\nWith colName<br \/>\n.MappingName = &#8220;ProductName&#8221;<br \/>\n.HeaderText = &#8220;Product Name&#8221;<br \/>\n.Width = 180<br \/>\nEnd With<br \/>\nAddHandler colName.TextBox.Validating, AddressOf CellValidating<\/p>\n<p>ts.GridColumnStyles.Add(colName)<br \/>\nts.GridColumnStyles.Add(colDiscontinued)<\/p>\n<p>DataGrid1.TableStyles.Add(ts)<\/p>\n<p>ts = Nothing<br \/>\ncolDiscontinued = Nothing<br \/>\ncolName = Nothing<\/p>\n<p>DataGrid1.DataSource = ds.Tables(&#8220;Products&#8221;)<br \/>\nEnd Sub<\/p>\n<p>Private Sub CellValidating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)<br \/>\nDebug.WriteLine(DirectCast(sender, DataGridTextBox).Text)<br \/>\nEnd Sub<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>To validate the text entered into a datagrid add a handler to the DatagridTextboxColumn&#8217;s validating event. Here is some sample code. Dim ds As New DataSet Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim conn As SqlConnection Dim strConn As String Dim strSQL As String Dim da As SqlDataAdapter strConn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[110],"tags":[34,40],"_links":{"self":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/80"}],"collection":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=80"}],"version-history":[{"count":0,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}