Connecting Tech Pros Worldwide Forums | Help | Site Map

Disable/Enable Controls (Textbox) in SplitContainer

Newbie
 
Join Date: Jul 2009
Posts: 14
#1: Oct 24 '09
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.

Newbie
 
Join Date: Jul 2009
Posts: 14
#2: Oct 24 '09

re: Disable/Enable Controls (Textbox) in SplitContainer


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
Newbie
 
Join Date: Jul 2009
Posts: 14
#3: 4 Weeks Ago

re: Disable/Enable Controls (Textbox) in SplitContainer


Problem above solved. My mistake.

I moved @Line 6 Public Class

Dim objDataAdapter As New SqlDataAdapter()

to LoadDatagrdCatalog()
Reply