473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Disable/Enable Controls (Textbox) in SplitContainer

Hello all,

Currently, I am building an Catalog Application where User can search, edit, add and delete Product_ID on a same form.

I am using Split Container (Vertical) to section out form's controls.
Panel1 (Top) contains Header of the Form, searchbar (plan - not constructed yet).
Panel2 (Bottom) has 1 DataGridView (Dock: Left) which display all Product_Item and connected to SQL Database.Also, 8 textboxes and label. Hence, whenever User clicked any row at DataGridView, extra data will be shown in the textboxes.

Question,
I would like a Loop to auto Disabled/Enabled these textboxes on form_load and a button_click.

I had tried:-

Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2. For Each ctl In Me.Panel2.Controls
  3.      If TypeOf ctl Is TextBox Then
  4.  
  5.           ctl.Enabled = False
  6.      End If
  7. Next
I am not really sure why it does not work.
Oct 24 '09 #1
2 3013
Problem Above solved!
I decided not to use Split Container and use TableLayoutPanel to section the Header and DataGridView. While my TextBoxes, they are located on the form as normal, without any Container.

However, a new problem popped-out when I trying to update my data.
[I am not sure whether I need to post a new topic since this is a not related problem]

Error: @ Line42
System.NullReferenceException
Object reference not set to an instance of an object


My Code for btnUpdate (button)

Expand|Select|Wrap|Line Numbers
  1. Public Class Catalog
  2.  
  3.     Dim objConnection As SqlConnection = New SqlConnection _
  4.         ("Data Source=WEIRDGUY-PC\SQLEXPRESS;Initial Catalog=StockInventory;Integrated Security=True")
  5.  
  6.     Dim objDataAdapter As New SqlDataAdapter()
  7.     Dim objDataSet As New DataSet
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
  2.  
  3.         If String.IsNullOrEmpty(txtItemID.Text) Then
  4.  
  5.             MsgBox("Error: Part Number is Empty!")
  6.             Exit Sub
  7.         End If
  8.  
  9.         If String.IsNullOrEmpty(txtCat.Text) Then
  10.  
  11.             MsgBox("Error: Category is Empty!")
  12.             Exit Sub
  13.         End If
  14.  
  15.         Try
  16.  
  17.             'Declare local variables and objects...
  18.             'Dim intPosition As Integer
  19.             Dim objCommand As SqlCommand = New SqlCommand()
  20.  
  21.             'Save the current record position
  22.             'intPosition = objCurrencyManager.Position
  23.  
  24.             objCommand.Connection = objConnection
  25.             objCommand.CommandText = "UPDATE dbo.Item " & _
  26.                                      "SET ItemDesc = @Desc, " & _
  27.                                          "ItemCat = @Cat, " & _
  28.                                          "ItemUnit = @Unit, " & _
  29.                                          "ItemLoc = @Loc, " & _
  30.                                          "ItemNotes = @Notes " & _
  31.                                          "WHERE ItemID = @ItemID"
  32.  
  33.             'Parameters for Description
  34.             objCommand.Parameters.AddWithValue("@Desc", txtDesc.Text)
  35.             objCommand.Parameters.AddWithValue("@Cat", txtCat.Text)
  36.             objCommand.Parameters.AddWithValue("@Unit", txtUnit.Text)
  37.             objCommand.Parameters.AddWithValue("@Loc", txtLoc.Text)
  38.             objCommand.Parameters.AddWithValue("@Notes", txtNotes.Text)
  39.             objCommand.Parameters.AddWithValue("@ItemID", txtItemID.Text)
  40.  
  41.  
  42.             objConnection.Open()    'Problem occurred at this line
  43.  
  44.             objCommand.ExecuteNonQuery()
  45.  
  46.             MessageBox.Show(txtItemID.Text & "had updated!")
  47.  
  48.             objConnection.Close()
  49.  
  50.         Catch ex As Exception
  51.             MsgBox(ex.Message)
  52.  
  53.  
  54.         End Try
  55.  
  56.     End Sub
  57. End Class
Oct 24 '09 #2
Problem above solved. My mistake.

I moved @Line 6 Public Class

Dim objDataAdapter As New SqlDataAdapter()

to LoadDatagrdCatalog()
Oct 26 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Lloyd | last post by:
How do you make a textbox enabled or disabled ??? i have tried Textbox.disable or enable but the controls apparently dont have this property programmically ???
0
by: Robert Ladd | last post by:
Hi, I'm trying to disable the asp.net calendar control from a javascript function, but it doesn't disable the doPostBack. To simplify the situation, assume a page with 4 controls. A...
0
by: dotnetkumar | last post by:
hi everybody, i am currently working with multipage and tabstrip controls. i want to disable the multipage and the controls inside it unless the user wants it to enable it. multipage.enable...
5
by: Edwin Knoppert | last post by:
I have a div which holds controls. I'm looking for a way to disable all controls but *without* setting each control enable state. Same to style>display i'm looking for a disable method. Do i...
4
by: Matrixreloadedth | last post by:
How to change disable color of Checkbox??? I have a checkbox with forecolor in red but when i disable by set Enable properties to false forecolor is changed to gray color but i don't want it. how...
4
by: disaia | last post by:
I saw the C# solution: for each Control c in Page.Controls if c is WebControl --((WebControl)c).Enabled = False / true / variable But could figure out the VB syntax. The closest I got was...
1
by: Martin | last post by:
Hi all ! I use Visual Studio .NET 2005 SP1 (+ Updates for Vista) on Windows Vista. I have a strange problem in a WinForm application. In a UserControl, which inherit another UserControl...
8
by: freeskier | last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when...
8
by: sebouh181 | last post by:
I am writing to registry using javascript. var wsh = new ActiveXObject("WScript.Shell"); var key = "HKLM\\Software\\Neos\\2.0\\LightMode\\my-script"; wsh.RegWrite (key, 1999, "REG_SZ"); when i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
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...

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.