binding to radio buttons for detail view form

Capstone project been woorking for a week on this.

Page 1 of 1

1 Replies - 5115 Views - Last Post: 09 July 2008 - 05:18 AM Rate Topic: -----

#1 debeth  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 07-July 08

binding to radio buttons for detail view form

Posted 09 July 2008 - 04:58 AM

Hi...
This is making me scream . My form is binded to every thing but the two radio buttons. Now one of my issues is this. I found a radio binding example and tried it. Well when my program executes it was working fine.
Then when i attemptted to bind these buttons the add_click method stopped cleariing the form not allowing a add to occur. But i think this is the right direction to bind the buttons.......Will somebody look and see for me


Public Class addChargeForm
	Private WithEvents aBindingSource As BindingSource
	Private Shared anInstance As addChargeForm
	Private chargeData As New PersonalTimeLogDataSet 'DATA SET
	Private addingBoolean As Boolean = False
	Private editingBoolean As Boolean = False
	Private previousSelectedIndex As Integer
	Private aChargeclass As chargeclass 'DATA TIER

	' Private ChargeCodeTableAdapter As New PersonalTimeLogDataSetTableAdapters.ChargeCodeTableAdapter



	Public Shared ReadOnly Property Instance() As addChargeForm
		Get
			If anInstance Is Nothing Then
				anInstance = New addChargeForm

			End If
			Return anInstance

		End Get
	End Property

	Private Sub addChargeForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'TODO: This line of code loads data into the 'PersonalTimeLogDataSet.ChargeCode' table. You can move, or remove it, as needed.


		''retrieve the data and bind the forms control


		With Me
			Try

				'creates the instance of data tier
				.aChargeclass = New chargeclass
				.chargeData = .aChargeclass.getachargeData()


				''set the binding source
				.aBindingSource = New BindingSource
				With .aBindingSource
					.DataSource = chargeData
					.DataMember = "ChargeCode"
					.Sort = "ChargeCode"
					.MoveLast()
					.MoveFirst()


				End With
				'combobox binding 
				With .codeTx
					.DataSource = aBindingSource
					.DisplayMember = "ChargeCode"
					.DataBindings.Add("text", aBindingSource, "ChargeCode", False, DataSourceUpdateMode.Never)
				End With

				''bind the other texts controls

				.titleTxt.DataBindings.Add("text", aBindingSource, "ChargeTitle")
				.descriptionTxt.DataBindings.Add("text", aBindingSource, "Description")
				.setControlsReadOnly(True)
				'bind the radio buttons
				.activeBtn.DataBindings.Add("checked", aBindingSource, "Status")
				.inactiveBtn.Checked = Not (activeBtn.Checked)









			Catch ex As Exception
				MessageBox.Show("Data error: " & ex.Message)
			End Try
		End With


	End Sub

	Private Sub addBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addBtn.Click
		' begin an add operation or cancel the current

		With Me
			If .addBtn.Text = "&Add" Then
				With aBindingSource
					.EndEdit()
					.AddNew()

				End With
				.addingBoolean = True
				.codeTxtBinding()
				.codeTx.Focus()
				.setControlsReadOnly(False)
				.setButtonsForEdit()
				'save the index of new record for later
				If .codeTx.SelectedIndex <> -1 Then
					.previousSelectedIndex = .codeTx.Items.Count - 1
				Else
					.previousSelectedIndex = 0
				End If
			Else
				'save(Button)
				Try
					.aBindingSource.EndEdit()
					.aChargeclass.update(chargeData)


					'.chargeData.AcceptChanges()
					.ToolStripStatusLabel1.Text = "Record committed to data set"

					.addingBoolean = False
					.editingBoolean = False
					.setControlsReadOnly(True)
					.resetButtonsForEdit()
					.codeTxtBinding()
					.codeTx.SelectedIndex = .previousSelectedIndex
				Catch ex As Exception
					'Catches error
					MessageBox.Show(ex.Message)
				End Try
			End If

		End With
	End Sub
	Private Sub setControlsReadOnly(ByVal valueBoolean As Boolean)
		'locks or unlocks the control
		With Me

			.titleTxt.ReadOnly = valueBoolean
			.descriptionTxt.ReadOnly = valueBoolean
			'.activeBtn.Checked = valueBoolean
			'.inactiveBtn.Enabled = valueBoolean





		End With
	End Sub
	Private Sub resetButtonsForEdit()

		'sets the buttons for add or edit
		With Me
			.addBtn.Text = "&Add"
			.cancelBtn.Text = "Delete"
			.EditBtn.Enabled = True
			'.ToolStripStatusLabel1.Text = String.Empty
		End With
	End Sub
	Private Sub setButtonsForEdit()
		'sets the add or edit buttons
		With Me
			.addBtn.Text = "Save"
			.cancelBtn.Text = "Cancel"
			.EditBtn.Enabled = False
			If .addingBoolean Then
				.ToolStripStatusLabel1.Text = "adding"
			Else
				.ToolStripStatusLabel1.Text = "Editing"
			End If
		End With
	End Sub
	Private Sub cancelBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelBtn.Click
		''Cancel
		Dim DeleteDialogResults As DialogResult

		

		With Me
			Try
				If cancelBtn.Text = " Delete" Then
					DeleteDialogResults = MessageBox.Show("delete this record?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
					If DeleteDialogResults = Windows.Forms.DialogResult.Yes Then
						With Me
							.aBindingSource.RemoveCurrent()
							.aChargeclass.update(chargeData)
							'.ChargeCodeTableAdapter.Update(.chargeData.ChargeCode)
							.ToolStripStatusLabel1.Text = "record deleted"

						End With
					End If
				Else
					'canceled button clicked
					If addingBoolean Then
						.previousSelectedIndex -= 1

					End If
					.aBindingSource.CancelEdit()
					.addingBoolean = False
					.editingBoolean = False
					.setControlsReadOnly(True)
					.resetButtonsForEdit()
					.codeTxtBinding()
					.codeTx.SelectedIndex  = .previousSelectedIndex
				End If

			Catch ex As Exception
				Dim messageString As String
				messageString = "Unable to complete the  operation: " & ex.Message
				MessageBox.Show(messageString, "Cancel", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

			End Try
		End With
	End Sub
	Private Sub codeTxtBinding()
		'set the combo box to save changes
		'saves for add or edit
		'sets the combo box to not allow drop-downs during an add or edit
		With Me.codeTx
			If (addingBoolean Or editingBoolean) Then
				.DataBindings!text.DataSourceUpdateMode = DataSourceUpdateMode.OnValidation
				.DropDownStyle = ComboBoxStyle.Simple
			Else
				.DataBindings!text.DataSourceUpdateMode = DataSourceUpdateMode.Never
				.DropDownStyle = ComboBoxStyle.DropDownList
			End If


		End With
	End Sub

	Private Sub ABindingSource_Positionchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles aBindingSource.Positionchanged
		'displays the postion and record number
		With Me.aBindingSource
			Me.ToolStripStatusLabel1.Text = "Record " & (.Position + 1).ToString() & " of " & .Count.ToString()



		End With
	End Sub

	Private Sub EditBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditBtn.Click
		' allows editting to the current record
		With Me
			.editingBoolean = True
			.setControlsReadOnly(False)
			.setButtonsForEdit()
			.previousSelectedIndex = .codeTx.SelectedIndex
			.codeTxtBinding()
		End With
	End Sub

	Private Sub addChargeForm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
		anInstance = Nothing
		Dim responseDialogResults As DialogResult
		With Me
			If .chargeData.HasChanges Then
				responseDialogResults = MessageBox.Show("Save the database changes ?", "Changed Data", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
				Select Case responseDialogResults
					Case Windows.Forms.DialogResult.Yes
						.aChargeclass.update(chargeData)

					Case Windows.Forms.DialogResult.Cancel
						e.Cancel = True
				End Select
			End If
		End With

	  

	End Sub


	Private Sub CloseBTn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseBTn.Click
		'Dim responseDialogResults As DialogResult
		'With Me
		'	If .chargeData.HasChanges Then
		'		responseDialogResults = MessageBox.Show("Save the database changes ?", "Changed Data", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
		'		Select Case responseDialogResults
		'			Case Windows.Forms.DialogResult.Yes
		'				.aChargeclass.update(chargeData)



		Me.Close()

		'		End Select
		'	End If
		'End With
	End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: binding to radio buttons for detail view form

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: binding to radio buttons for detail view form

Posted 09 July 2008 - 05:18 AM

Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1