I'm using the .EndEdit and the .Update for saving my records in datagridview. I'm also using access database which has 145 fields in one table. I'm keep getting a an unhandled exception in... error with an additional message Too many fields defined when saving an edited record. It is working fine when adding/saving new records. Is my field too many? I've read that the access has 255 fields limit per table...
Imports System.Data.OleDb
Public Class Info
Inherits System.Windows.Forms.Form
Private Sub bday1_ValueChanged(sender As Object, e As EventArgs) Handles bday.ValueChanged
Dim d1, d2 As Date
Dim days, months, years As Long
d1 = bday.Value.ToShortDateString
d2 = Now.ToShortDateString
years = Year(d1)
months = Month(d1)
days = d1.Day
years = Year(d2) - years
months = Month(d2) - months
days = d2.Day - days
If Math.Sign(days) = -1 Then
days = 30 - Math.Abs(days)
months = months - 1
End If
If Math.Sign(months) = -1 Then
months = 12 - Math.Abs(months)
years = years - 1
End If
age.Text = years.ToString
'TextBox2.Text = months.ToString
'TextBox3.Text = days.ToString
End Sub
Private Sub add1_Click(sender As Object, e As EventArgs) Handles add1.Click
comname2.Enabled = True
posi2.Enabled = True
deptm2.Enabled = True
tm2.Enabled = True
reason2.Enabled = True
add2.Enabled = True
End Sub
Private Sub add2_Click(sender As Object, e As EventArgs) Handles add2.Click
comname3.Enabled = True
posi3.Enabled = True
deptm3.Enabled = True
tm3.Enabled = True
reason3.Enabled = True
add3.Enabled = True
End Sub
Private Sub add3_Click(sender As Object, e As EventArgs) Handles add3.Click
comname4.Enabled = True
posi4.Enabled = True
deptm4.Enabled = True
tm4.Enabled = True
reason4.Enabled = True
add4.Enabled = True
End Sub
Private Sub add4_Click(sender As Object, e As EventArgs) Handles add4.Click
comname5.Enabled = True
posi5.Enabled = True
deptm5.Enabled = True
tm5.Enabled = True
reason5.Enabled = True
add5.Enabled = True
End Sub
Private Sub add5_Click(sender As Object, e As EventArgs) Handles add5.Click
comname6.Enabled = True
posi6.Enabled = True
deptm6.Enabled = True
tm6.Enabled = True
reason6.Enabled = True
add6.Enabled = True
End Sub
Private Sub add6_Click(sender As Object, e As EventArgs) Handles add6.Click
comname7.Enabled = True
posi7.Enabled = True
deptm7.Enabled = True
tm7.Enabled = True
reason7.Enabled = True
add7.Enabled = True
End Sub
Private Sub add7_Click(sender As Object, e As EventArgs) Handles add7.Click
comname8.Enabled = True
posi8.Enabled = True
deptm8.Enabled = True
tm8.Enabled = True
reason8.Enabled = True
add8.Enabled = True
End Sub
Private Sub add8_Click(sender As Object, e As EventArgs) Handles add8.Click
comname9.Enabled = True
posi9.Enabled = True
deptm9.Enabled = True
tm9.Enabled = True
reason9.Enabled = True
add9.Enabled = True
End Sub
Private Sub add9_Click(sender As Object, e As EventArgs) Handles add9.Click
comname10.Enabled = True
posi10.Enabled = True
deptm10.Enabled = True
tm10.Enabled = True
reason10.Enabled = True
End Sub
Private Sub Info_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the '_Employees__RecordDataSet._employees__record' table. You can move, or remove it, as needed.
Me.Employees__recordTableAdapter.Fill(Me._Employees__RecordDataSet._employees__record)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Add.Click
EmployeesRecordBindingSource.AddNew()
TextBox1.Text = getAutoId
enableall()
End Sub
Private Function getAutoId() As Integer
If Me.DataGridView.Rows.Count = 0 Then
getAutoId = 1
Else
getAutoId = Me.DataGridView.Rows(Me.DataGridView.Rows.Count - 1).Cells(0).Value + 0
End If
End Function
Private Sub btnReg_Click(sender As Object, e As EventArgs) Handles btnReg.Click
On Error GoTo dito
Dim D1, D2, D3, D4 As Date
D1 = bday.Value.ToShortDateString
D2 = Now.ToShortDateString
D3 = date1.Value.ToShortDateString
D4 = date1.Value.ToShortDateString
If D1 >= D2 Then
MessageBox.Show("Birthday must not be less than or equal to current date!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
bday.Value = Now.Date
ElseIf fname.Text = "" Then
MessageBox.Show("Insert First Name Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf lname.Text = "" Then
MessageBox.Show("Insert Last Name Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf mi.Text = "" Then
MessageBox.Show("Insert Middle Initial Name Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf address.Text = "" Then
MessageBox.Show("Insert Address Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf age.Text <= 17 Then
MessageBox.Show("Age must be 18yrs. and above.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf sex.Text = "" Then
MessageBox.Show("Choose Sex Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf contact.Text = "" Then
MessageBox.Show("Insert Contact Number Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf dept1.Text = "" Then
MessageBox.Show("Insert Department Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf pos1.Text = "" Then
MessageBox.Show("Insert Position Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf civil.Text = "" Then
MessageBox.Show("Choose Civil Status Please!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
EmployeesRecordBindingSource.EndEdit()
Employees__recordTableAdapter.Update(Me._Employees__RecordDataSet._employees__record)
MessageBox.Show("Record Save!", "Success!")
disableall()
End If
dito:
Exit Sub
End Sub
Private Sub civil_SelectedIndexChanged(sender As Object, e As EventArgs)
If civil.SelectedItem = "Married" Then
spouse.Enabled = True
ElseIf civil.SelectedItem = "Widowed" Then
spouse.Enabled = True
ElseIf civil.SelectedItem = "Legally Separated" Then
spouse.Enabled = True
ElseIf civil.SelectedItem = "Anulled" Then
spouse.Enabled = True
Else
spouse.Enabled = False
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
enableall()
End Sub
Private Sub enableall()
lname.Enabled = True
fname.Enabled = True
mi.Enabled = True
bday.Enabled = True
sex.Enabled = True
natio.Enabled = True
address.Enabled = True
contact.Enabled = True
father.Enabled = True
mother.Enabled = True
tin.Enabled = True
sss.Enabled = True
pagibig.Enabled = True
phh.Enabled = True
stat.Enabled = True
dept1.Enabled = True
pos1.Enabled = True
rm.Enabled = True
date1.Enabled = True
civil.Enabled = True
termiresi.Enabled = True
date2.Enabled = True
heduc.Enabled = True
elem.Enabled = True
y1.Enabled = True
hs.Enabled = True
y2.Enabled = True
col.Enabled = True
y3.Enabled = True
deg.Enabled = True
pdeg.Enabled = True
ts.Enabled = True
y4.Enabled = True
other.Enabled = True
childno.Enabled = True
childone.Enabled = True
childtwo.Enabled = True
childthree.Enabled = True
childfour.Enabled = True
childfive.Enabled = True
childsix.Enabled = True
childseven.Enabled = True
childeight.Enabled = True
childnine.Enabled = True
btnReg.Enabled = True
End Sub
Private Sub disableall()
lname.Enabled = False
fname.Enabled = False
mi.Enabled = False
bday.Enabled = False
sex.Enabled = False
natio.Enabled = False
address.Enabled = False
contact.Enabled = False
father.Enabled = False
mother.Enabled = False
tin.Enabled = False
sss.Enabled = False
pagibig.Enabled = False
phh.Enabled = False
stat.Enabled = False
dept1.Enabled = False
pos1.Enabled = False
rm.Enabled = False
date1.Enabled = False
civil.Enabled = False
termiresi.Enabled = False
date2.Enabled = False
heduc.Enabled = False
elem.Enabled = False
y1.Enabled = False
hs.Enabled = False
y2.Enabled = False
col.Enabled = False
y3.Enabled = False
deg.Enabled = False
pdeg.Enabled = False
ts.Enabled = False
y4.Enabled = False
other.Enabled = False
Add.Enabled = True
btnReg.Enabled = False
childno.Enabled = False
childone.Enabled = False
childtwo.Enabled = False
childthree.Enabled = False
childfour.Enabled = False
childfive.Enabled = False
childsix.Enabled = False
childseven.Enabled = False
childeight.Enabled = False
childnine.Enabled = False
End Sub
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
childno.Enabled = True
childone.Enabled = True
childtwo.Enabled = True
childthree.Enabled = True
childfour.Enabled = True
childfive.Enabled = True
childsix.Enabled = True
childseven.Enabled = True
childeight.Enabled = True
childnine.Enabled = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
On Error GoTo dire
If MessageBox.Show("Are you sure?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
EmployeesRecordBindingSource.RemoveCurrent()
Employees__recordTableAdapter.Update(Me._Employees__RecordDataSet._employees__record)
End If
dire:
Exit Sub
End Sub
End Class
Related
I want to use AutoSize of TableLayoutPanel and FlowLayoutPanel to layout my Controls. After the parent Control has been layed out I want to freeze the layout, so if I hide a control, nothing should collapse. So I want to use Control.Visible but without collapsing it.
Background information: I have a Control that supports multiple languages. I want the design to adjust to the language automatically. If I click a CheckBox then sometimes some Controls are hiding or showing, which causes the whole design to change if I use AutoSize. I don't want the Controls to collapse, I just want the Controls to show the background of the parent Control and keep the size.
Example (vb.net)
Form1.vb
Public Class Form1
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Label1.Visible = CheckBox1.Checked
End Sub
End Class
Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Wird vom Windows Form-Designer benötigt.
Private components As System.ComponentModel.IContainer
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
Me.Label1 = New System.Windows.Forms.Label()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.TableLayoutPanel1.SuspendLayout()
Me.SuspendLayout()
'
'TableLayoutPanel1
'
Me.TableLayoutPanel1.AutoSize = True
Me.TableLayoutPanel1.ColumnCount = 1
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle())
Me.TableLayoutPanel1.Controls.Add(Me.Label1, 0, 0)
Me.TableLayoutPanel1.Controls.Add(Me.CheckBox1, 0, 1)
Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.TableLayoutPanel1.Location = New System.Drawing.Point(0, 0)
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
Me.TableLayoutPanel1.RowCount = 2
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.Size = New System.Drawing.Size(800, 450)
Me.TableLayoutPanel1.TabIndex = 0
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(3, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'CheckBox1
'
Me.CheckBox1.AutoSize = True
Me.CheckBox1.Checked = True
Me.CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked
Me.CheckBox1.Location = New System.Drawing.Point(3, 16)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(81, 17)
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "CheckBox1"
Me.CheckBox1.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.AutoSize = True
Me.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.TableLayoutPanel1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.TableLayoutPanel1.ResumeLayout(False)
Me.TableLayoutPanel1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TableLayoutPanel1 As TableLayoutPanel
Friend WithEvents Label1 As Label
Friend WithEvents CheckBox1 As CheckBox
End Class
Result:
I want the controls to not move around. I want the controls to keep the size if the label is hidden. The label should not collapse but paint the background of the parent control instead.
The best solution that I am sort of happy with is to write my own custom Panel that implements the desired behavior and put the target control into that custom Panel. The trick is to add a normal Panel to my custom Panel that hides the target control if Visible is changed to false.
Solution in VB.NET
NoCollapsePanel.vb
Public Class NoCollapsePanel
Public Enum VisibleModeE
Collapse
KeepSize
End Enum
Public Property VisibleMode As VisibleModeE
Get
Return _VisibleMode
End Get
Set
If Value = VisibleMode Then Return
_VisibleMode = Value
RefreshVisibility()
End Set
End Property
Private Sub RefreshVisibility()
If _Visible Then Controls.Remove(hidePanel)
Select Case VisibleMode
Case VisibleModeE.Collapse
MyBase.Visible = _Visible
Case VisibleModeE.KeepSize
MyBase.Visible = True
If Not Visible Then
' this is doing the trick
hidePanel.Size = Size
Controls.Add(hidePanel)
hidePanel.BringToFront()
End If
End Select
End Sub
Public Shadows Event VisibleChanged As EventHandler
Private ReadOnly hidePanel As New Panel() With {.Margin = New Padding(0)}
Private _Visible As Boolean = True
Private _VisibleMode As VisibleModeE = VisibleModeE.KeepSize
Public Overloads Property Visible As Boolean
Get
Return _Visible
End Get
Set
If _Visible = Value Then Return
_Visible = Value
RefreshVisibility()
RaiseEvent VisibleChanged(Me, New EventArgs())
End Set
End Property
Protected Overrides Sub OnResize(eventargs As EventArgs)
MyBase.OnResize(eventargs)
hidePanel.Size = Size
End Sub
End Class
NoCollapsePanel.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class NoCollapsePanel
Inherits System.Windows.Forms.Panel
'Das Steuerelement überschreibt den Löschvorgang zum Bereinigen der Komponentenliste.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Wird vom Steuerelement-Designer benötigt.
Private components As System.ComponentModel.IContainer
' Hinweis: Die folgende Prozedur ist für den Komponenten-Designer erforderlich.
' Sie kann mit dem Komponenten-Designer geändert werden. Das Bearbeiten mit
' dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
End Class
Testing the Panel
Form1.vb
Public Class Form1
Public Sub New()
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
ComboBox1.DataSource = System.Enum.GetValues(GetType(NoCollapsePanel.VisibleModeE))
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
NoCollapsePanel1.Visible = CheckBox1.Checked
End Sub
Private rnd As New Random
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BackColor = Color.FromArgb(255, rnd.Next(255), rnd.Next(255), rnd.Next(255))
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
Label1.Text = If(CheckBox2.Checked, "some text", "some very very very very long text")
End Sub
Private Sub NoCollapsePanel1_VisibleChanged(sender As Object, e As EventArgs) Handles NoCollapsePanel1.VisibleChanged
TestVisibleChanged_Label.Text = DateTime.Now
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
NoCollapsePanel1.VisibleMode = ComboBox1.SelectedValue
End Sub
End Class
Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Wird vom Windows Form-Designer benötigt.
Private components As System.ComponentModel.IContainer
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.CheckBox2 = New System.Windows.Forms.CheckBox()
Me.TestVisibleChanged_Label = New System.Windows.Forms.Label()
Me.FlowLayoutPanel2 = New System.Windows.Forms.FlowLayoutPanel()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.NoCollapsePanel1 = New WindowsApp4.NoCollapsePanel()
Me.FlowLayoutPanel1 = New System.Windows.Forms.FlowLayoutPanel()
Me.Label1 = New System.Windows.Forms.Label()
Me.TableLayoutPanel1.SuspendLayout()
Me.FlowLayoutPanel2.SuspendLayout()
Me.NoCollapsePanel1.SuspendLayout()
Me.FlowLayoutPanel1.SuspendLayout()
Me.SuspendLayout()
'
'TableLayoutPanel1
'
Me.TableLayoutPanel1.AutoSize = True
Me.TableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.TableLayoutPanel1.ColumnCount = 1
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle())
Me.TableLayoutPanel1.Controls.Add(Me.NoCollapsePanel1, 0, 0)
Me.TableLayoutPanel1.Controls.Add(Me.CheckBox1, 0, 1)
Me.TableLayoutPanel1.Controls.Add(Me.Button1, 0, 2)
Me.TableLayoutPanel1.Controls.Add(Me.CheckBox2, 0, 3)
Me.TableLayoutPanel1.Controls.Add(Me.TestVisibleChanged_Label, 0, 4)
Me.TableLayoutPanel1.Controls.Add(Me.ComboBox1, 0, 5)
Me.TableLayoutPanel1.Location = New System.Drawing.Point(3, 3)
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
Me.TableLayoutPanel1.RowCount = 6
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.Size = New System.Drawing.Size(127, 134)
Me.TableLayoutPanel1.TabIndex = 1
'
'CheckBox1
'
Me.CheckBox1.AutoSize = True
Me.CheckBox1.Checked = True
Me.CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked
Me.CheckBox1.Location = New System.Drawing.Point(3, 22)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(83, 17)
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "Show Panel"
Me.CheckBox1.UseVisualStyleBackColor = True
'
'Button1
'
Me.Button1.AutoSize = True
Me.Button1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.Button1.Location = New System.Drawing.Point(3, 45)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(106, 23)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Change BackColor"
Me.Button1.UseVisualStyleBackColor = True
'
'CheckBox2
'
Me.CheckBox2.AutoSize = True
Me.CheckBox2.Location = New System.Drawing.Point(3, 74)
Me.CheckBox2.Name = "CheckBox2"
Me.CheckBox2.Size = New System.Drawing.Size(92, 17)
Me.CheckBox2.TabIndex = 3
Me.CheckBox2.Text = "Change Label"
Me.CheckBox2.UseVisualStyleBackColor = True
'
'TestVisibleChanged_Label
'
Me.TestVisibleChanged_Label.AutoSize = True
Me.TestVisibleChanged_Label.Location = New System.Drawing.Point(3, 94)
Me.TestVisibleChanged_Label.Name = "TestVisibleChanged_Label"
Me.TestVisibleChanged_Label.Size = New System.Drawing.Size(88, 13)
Me.TestVisibleChanged_Label.TabIndex = 4
Me.TestVisibleChanged_Label.Text = "Visibility changed"
'
'FlowLayoutPanel2
'
Me.FlowLayoutPanel2.AutoSize = True
Me.FlowLayoutPanel2.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.FlowLayoutPanel2.Controls.Add(Me.TableLayoutPanel1)
Me.FlowLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill
Me.FlowLayoutPanel2.Location = New System.Drawing.Point(0, 0)
Me.FlowLayoutPanel2.Name = "FlowLayoutPanel2"
Me.FlowLayoutPanel2.Size = New System.Drawing.Size(800, 450)
Me.FlowLayoutPanel2.TabIndex = 2
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Location = New System.Drawing.Point(3, 110)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
Me.ComboBox1.TabIndex = 5
'
'NoCollapsePanel1
'
Me.NoCollapsePanel1.AutoSize = True
Me.NoCollapsePanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.NoCollapsePanel1.Controls.Add(Me.FlowLayoutPanel1)
Me.NoCollapsePanel1.Location = New System.Drawing.Point(3, 3)
Me.NoCollapsePanel1.Name = "NoCollapsePanel1"
Me.NoCollapsePanel1.Size = New System.Drawing.Size(45, 13)
Me.NoCollapsePanel1.TabIndex = 0
Me.NoCollapsePanel1.VisibleMode = WindowsApp4.NoCollapsePanel.VisibleModeE.KeepSize
'
'FlowLayoutPanel1
'
Me.FlowLayoutPanel1.AutoSize = True
Me.FlowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.FlowLayoutPanel1.Controls.Add(Me.Label1)
Me.FlowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.FlowLayoutPanel1.Location = New System.Drawing.Point(0, 0)
Me.FlowLayoutPanel1.Name = "FlowLayoutPanel1"
Me.FlowLayoutPanel1.Size = New System.Drawing.Size(45, 13)
Me.FlowLayoutPanel1.TabIndex = 1
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(3, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.AutoSize = True
Me.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.ClientSize = New System.Drawing.Size(800, 450)
Me.Controls.Add(Me.FlowLayoutPanel2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.TableLayoutPanel1.ResumeLayout(False)
Me.TableLayoutPanel1.PerformLayout()
Me.FlowLayoutPanel2.ResumeLayout(False)
Me.FlowLayoutPanel2.PerformLayout()
Me.NoCollapsePanel1.ResumeLayout(False)
Me.NoCollapsePanel1.PerformLayout()
Me.FlowLayoutPanel1.ResumeLayout(False)
Me.FlowLayoutPanel1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents NoCollapsePanel1 As NoCollapsePanel
Friend WithEvents Label1 As Label
Friend WithEvents FlowLayoutPanel1 As FlowLayoutPanel
Friend WithEvents TableLayoutPanel1 As TableLayoutPanel
Friend WithEvents CheckBox1 As CheckBox
Friend WithEvents FlowLayoutPanel2 As FlowLayoutPanel
Friend WithEvents Button1 As Button
Friend WithEvents CheckBox2 As CheckBox
Friend WithEvents TestVisibleChanged_Label As Label
Friend WithEvents ComboBox1 As ComboBox
End Class
Is it possible that I can add keyevents in my timer. I know I can add mouse events but when I try to run the following code in the timer SUB: if e.keycode keys.E then msgbox.show("Bla bla bla") end if. It says you can only add tick events. Thanks for your time.
,,,,Public Class Form2
Private Sub Form2_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.W Then
W.BackColor = Color.White
End If
If e.KeyCode = Keys.S Then
Label2.BackColor = Color.White
End If
If e.KeyCode = Keys.A Then
Label1.BackColor = Color.White
End If
If e.KeyCode = Keys.D Then
Label3.BackColor = Color.White
End If
End Sub
Private Sub Form2_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.W Then
W.BackColor = Color.Gray
End If
If e.KeyCode = Keys.S Then
Label2.BackColor = Color.Gray
End If
If e.KeyCode = Keys.A Then
Label1.BackColor = Color.Gray
End If
If e.KeyCode = Keys.D Then
Label3.BackColor = Color.Gray
End If
End Sub
'just some stuff
Private Sub Form2_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
If Button.MouseButtons = MouseButtons.Left Then
Label4.BackColor = Color.White
End If
If Button.MouseButtons = MouseButtons.Right Then
Label5.BackColor = Color.White
End If
End Sub
Private Sub Form2_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then
Label4.BackColor = Color.Gray
End If
If e.Button = MouseButtons.Right Then
Label5.BackColor = Color.Gray
End If
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TopMost = True
Timer1.Start()
End Sub
'my problem
Private Sub Timer1_Tick(sender As Object, e As KeyEventArgs) Handles Timer1.Tick
If e.KeyCode = Keys.W Then
W.BackColor = Color.White
End If
End Sub
End Class,,,,,
I have a Winforms app with two ListViews in a SplitContainer.
When I drag the splitter to hide part of the Panel2 ListView items, it automatically adds a vertical scrollbar.
When I drag the splitter to hide part of the Panel1 ListView items, it does not add a vertical scrollbar.
Changing which ListView is in which Panel has the same behavior. It's as if something about the SplitContainer or its panels is controlling whether the vertical scrollbar is added to the ListView in Panel1 or not. How to make whichever ListView is in the top Panel1 also automatically add the vertical scrollbar?
To replicate, create a simple Winforms application with one form. Here is my form code followed by the designer form code.
Public Class Form1
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Timer1.Enabled = False
TechDateList.BeginUpdate()
TechDateList.Items.Clear()
StopsList.BeginUpdate()
StopsList.Items.Clear()
For i As Integer = 1 To 5
Dim techItem = New ListViewItem
techItem.UseItemStyleForSubItems = False
techItem.SubItems(0).Text = Date.Now.ToString("MMM dd, yyyy")
techItem.SubItems.Add(String.Format("Tech {0}", i))
TechDateList.Items.Add(techItem)
Next
For i As Integer = 1 To 5
Dim stopItem = New ListViewItem
stopItem.UseItemStyleForSubItems = False
stopItem.SubItems(0).Text = Choose(i, "AAA", "BBB", "CCC", "DDD", "EEE")
stopItem.SubItems.Add(String.Format("Stop {0}", i))
StopsList.Items.Add(stopItem)
Next
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Timer1_Tick Error 1")
Finally
TechDateList.EndUpdate()
StopsList.EndUpdate()
End Try
Try
ListSplitter.Panel1Collapsed = False
ListSplitter.SplitterDistance = 125
ListSplitter.SplitterWidth = 6
TechDateList.Items.Item(0).Selected = True
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Timer1_Tick Error 2")
End Try
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.ListSplitter = New System.Windows.Forms.SplitContainer()
Me.TechDateList = New System.Windows.Forms.ListView()
Me.UInitial = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.SchedDate = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.StopsList = New System.Windows.Forms.ListView()
Me.StopNum = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.StopName = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
CType(Me.ListSplitter, System.ComponentModel.ISupportInitialize).BeginInit()
Me.ListSplitter.Panel1.SuspendLayout()
Me.ListSplitter.Panel2.SuspendLayout()
Me.ListSplitter.SuspendLayout()
Me.SuspendLayout()
'
'ListSplitter
'
Me.ListSplitter.Dock = System.Windows.Forms.DockStyle.Fill
Me.ListSplitter.FixedPanel = System.Windows.Forms.FixedPanel.Panel1
Me.ListSplitter.Location = New System.Drawing.Point(0, 0)
Me.ListSplitter.Name = "ListSplitter"
Me.ListSplitter.Orientation = System.Windows.Forms.Orientation.Horizontal
'
'ListSplitter.Panel1
'
Me.ListSplitter.Panel1.Controls.Add(Me.TechDateList)
Me.ListSplitter.Panel1Collapsed = True
Me.ListSplitter.Panel1MinSize = 0
'
'ListSplitter.Panel2
'
Me.ListSplitter.Panel2.Controls.Add(Me.StopsList)
Me.ListSplitter.Size = New System.Drawing.Size(384, 261)
Me.ListSplitter.SplitterDistance = 25
Me.ListSplitter.SplitterWidth = 1
Me.ListSplitter.TabIndex = 1
'
'TechDateList
'
Me.TechDateList.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.TechDateList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.UInitial, Me.SchedDate})
Me.TechDateList.FullRowSelect = True
Me.TechDateList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None
Me.TechDateList.HideSelection = False
Me.TechDateList.LabelWrap = False
Me.TechDateList.Location = New System.Drawing.Point(4, 0)
Me.TechDateList.Margin = New System.Windows.Forms.Padding(0)
Me.TechDateList.MultiSelect = False
Me.TechDateList.Name = "TechDateList"
Me.TechDateList.ShowGroups = False
Me.TechDateList.Size = New System.Drawing.Size(258, 166)
Me.TechDateList.TabIndex = 0
Me.TechDateList.UseCompatibleStateImageBehavior = False
Me.TechDateList.View = System.Windows.Forms.View.Details
'
'UInitial
'
Me.UInitial.Text = "Route"
Me.UInitial.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
Me.UInitial.Width = 100
'
'SchedDate
'
Me.SchedDate.Text = "Job Date"
Me.SchedDate.Width = 133
'
'StopsList
'
Me.StopsList.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.StopsList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.StopNum, Me.StopName})
Me.StopsList.FullRowSelect = True
Me.StopsList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None
Me.StopsList.HideSelection = False
Me.StopsList.LabelWrap = False
Me.StopsList.Location = New System.Drawing.Point(4, 0)
Me.StopsList.Margin = New System.Windows.Forms.Padding(0)
Me.StopsList.MultiSelect = False
Me.StopsList.Name = "StopsList"
Me.StopsList.ShowGroups = False
Me.StopsList.Size = New System.Drawing.Size(258, 252)
Me.StopsList.TabIndex = 0
Me.StopsList.UseCompatibleStateImageBehavior = False
Me.StopsList.View = System.Windows.Forms.View.Details
'
'StopNum
'
Me.StopNum.Text = "000"
Me.StopNum.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
Me.StopNum.Width = 34
'
'StopName
'
Me.StopName.Text = "Stop Name"
Me.StopName.Width = 199
'
'Timer1
'
Me.Timer1.Interval = 250
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(384, 261)
Me.Controls.Add(Me.ListSplitter)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ListSplitter.Panel1.ResumeLayout(False)
Me.ListSplitter.Panel2.ResumeLayout(False)
CType(Me.ListSplitter, System.ComponentModel.ISupportInitialize).EndInit()
Me.ListSplitter.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Friend WithEvents ListSplitter As SplitContainer
Friend WithEvents TechDateList As ListView
Friend WithEvents UInitial As ColumnHeader
Friend WithEvents SchedDate As ColumnHeader
Friend WithEvents StopsList As ListView
Friend WithEvents StopNum As ColumnHeader
Friend WithEvents StopName As ColumnHeader
Friend WithEvents Timer1 As Timer
End Class
From what I see in Designer code, TechDateList Height exceeds ListSplitter.Panel1 Height:
Me.ListSplitter.SplitterDistance = 25
Me.TechDateList.Size = New System.Drawing.Size(258, 166)
make sure that TechDateList fits Panel1 in Designer, e.g
Me.ListSplitter.SplitterDistance = 125
Me.TechDateList.Size = New System.Drawing.Size(258, 120)
and then resize will work as expected.
consider also docking TechDateList to Left - the list will get maximum possible Height and will resize with Panel1
I'm guessing that moving the splitter is resizing the ListView in Panel2 but not resizing the ListView in Panel1. I'm probably missing something simple somewhere. Regardless, if I add this code to the form, I get the desired results:
Private Sub ListSplitter_SplitterMoved(sender As Object, e As SplitterEventArgs) Handles ListSplitter.SplitterMoved
TechDateList.Height = ListSplitter.Panel1.Height
End Sub
We use ToggleEdit (to enable/disable controls) when navigating to a new page in a new tab. This time the new tab is created in an existing page. It works as it should the first time the grid is loaded, but then fails the second time. Have tried lots of different methods but still the same result
Double clicking a row in a DataGrid causes a new tab to be opened
Private Sub Alarm_Edit(sender As Object, e As RoutedEventArgs)
Try
e.Handled = True
IsNewRecord = False
Dim DGV As DGVx = PersonalSchedule_Grid.FindName("Schedule_AlarmsDGV")
If DGV.SelectedItems.Count = 1 Then
Dim row As System.Data.DataRowView = DGV.SelectedItems(0)
Alarm_ID = row("ID")
Dim vName As String = row("Subject")
Dim vTab As STC_Tabx = PersonalSchedule_Grid.FindName(TabName)
Dim TabControl As STCx = PersonalSchedule_Grid.FindName("Alarm_TabControl")
If Not vTab Is Nothing Then
vTab.Close()
End If
Dim MCFrame As New Frame
Dim MCTab As New STC_Tabx
With MCTab
.Name = TabName
.Header = " " & Left(vName, 20) & " "
.ImageSource = ReturnImageAsString("Edit.png", 16)
.CloseButtonVisibility = DevComponents.WpfEditors.eTabCloseButtonVisibility.Visible
.TabToolTip = "View or edit the " & vName & " record"
' .Content = MCFrame
.Content = AlarmGrid()
End With
RemoveHandler MCTab.Closing, AddressOf TabControl_TabClosing
AddHandler MCTab.Closing, AddressOf TabControl_TabClosing
RegisterControl(PersonalSchedule_Grid, MCTab)
TabControl.Items.Add(MCTab)
' MCFrame.NavigationService.Navigate(AlarmPage)
LoadedTabs(TabName)
MCTab.IsSelected = True
End If
Catch ex As Exception
EmailError(ex)
End Try
End Sub
... and this is added to the tab
Private Function AlarmGrid() As Grid
Try
Dim MainGrid As New Grid
MainGrid.Children.Clear()
Dim vGrid As New Grid
vGrid.ColumnDefinitions.Clear()
vGrid.RowDefinitions.Clear()
vGrid.Children.Clear()
Dim SV As New ScrollViewer
With SV
.Name = "Alarm_SV"
.Content = vGrid
.VerticalScrollBarVisibility = ScrollBarVisibility.Auto
End With '
RegisterControl(PersonalSchedule_Grid, SV)
MainGrid.Children.Add(SV)
For i As Integer = 0 To 5
Dim vRow As New RowDefinition
If i = 4 Then
vRow.Height = New GridLength(35, GridUnitType.Star)
Else
vRow.Height = New GridLength(35)
End If
vGrid.RowDefinitions.Add(vRow)
Next
For i As Integer = 0 To 1
Dim vCol As New ColumnDefinition
If i = 0 Then
vCol.Width = New GridLength(120)
ElseIf i = 1 Then
vCol.Width = New GridLength(200, GridUnitType.Star)
End If
vGrid.ColumnDefinitions.Add(vCol)
Next
'Date | Time | Subject | Details
Dim vToolBar As New ToolBar
Grid.SetColumn(vToolBar, 0)
Grid.SetColumnSpan(vToolBar, 2)
Grid.SetRow(vToolBar, 0)
vGrid.Children.Add(vToolBar)
Dim EditButton As New Button
With EditButton
.Content = ReturnToolBarImage("Edit.png")
.Name = "Alarm_EditButton"
.ToolTip = "Edit the record"
If IsNewRecord = True Then
.Visibility = Visibility.Collapsed
End If
End With
RegisterControl(PersonalSchedule_Grid, EditButton)
vToolBar.Items.Add(EditButton)
Dim EditTS As New Separator
With EditTS
.Name = "Alarm_EditTS"
If IsNewRecord = True Then
.Visibility = Visibility.Collapsed
End If
End With
RegisterControl(PersonalSchedule_Grid, EditTS)
vToolBar.Items.Add(EditTS)
Dim SaveUpdateButton As New Button
With SaveUpdateButton
.Name = "Alarm_SaveUpdateButton"
If IsNewRecord = True Then
.Content = ReturnToolBarImage("Record_Insert.png")
.ToolTip = "Save the record"
.IsEnabled = True
Else
.Content = ReturnToolBarImage("Record_Update.png")
.ToolTip = "Update the record"
.IsEnabled = False
End If
End With
RegisterControl(PersonalSchedule_Grid, SaveUpdateButton)
vToolBar.Items.Add(SaveUpdateButton)
vToolBar.Items.Add(TS_Separator)
Dim EnabledCB As New CBx
With EnabledCB
.Content = "Enabled"
.ToolTip = "The alarm is enabled"
.Name = "Alarm_EnabledCB"
.IsNewRecord = IsNewRecord
If IsNewRecord = True Then
.Visibility = Visibility.Collapsed
End If
End With
RegisterControl(PersonalSchedule_Grid, EnabledCB)
vToolBar.Items.Add(EnabledCB)
If IsNewRecord = False Then
vToolBar.Items.Add(TS_Separator)
End If
Dim DateLB As New TextLabel
With DateLB
.Text = "Date"
End With
Grid.SetColumn(DateLB, 0)
Grid.SetRow(DateLB, 1)
vGrid.Children.Add(DateLB)
Dim DateTB As New DateTBx
With DateTB
.IsNewRecord = IsNewRecord
.Value = Today
.Name = "Alarm_DateTB"
End With
RegisterControl(PersonalSchedule_Grid, DateTB)
Grid.SetColumn(DateTB, 1)
Grid.SetRow(DateTB, 1)
vGrid.Children.Add(DateTB)
Dim TimeLB As New TextLabel
With TimeLB
.Text = "Time"
End With
Grid.SetColumn(TimeLB, 0)
Grid.SetRow(TimeLB, 2)
vGrid.Children.Add(TimeLB)
Dim TimeTB As New TimeTBx
With TimeTB
.Value = Format(DateTime.Now, "HH:mm")
.IsNewRecord = IsNewRecord
.Name = "Alarm_TimeTB"
End With
RegisterControl(PersonalSchedule_Grid, TimeTB)
Grid.SetColumn(TimeTB, 1)
Grid.SetRow(TimeTB, 2)
vGrid.Children.Add(TimeTB)
Dim SubjectLB As New TextLabel
With SubjectLB
.Text = "Subject"
End With
Grid.SetColumn(SubjectLB, 0)
Grid.SetRow(SubjectLB, 3)
vGrid.Children.Add(SubjectLB)
Dim SubjectTB As New TBx
With SubjectTB
.Width = 300
.IsNewRecord = IsNewRecord
.Name = "Alarm_SubjectTB"
End With
RegisterControl(PersonalSchedule_Grid, SubjectTB)
Grid.SetColumn(SubjectTB, 1)
Grid.SetRow(SubjectTB, 3)
vGrid.Children.Add(SubjectTB)
Dim DetailsLB As New TextBlock
With DetailsLB
.Text = "Details"
.VerticalAlignment = VerticalAlignment.Top
.HorizontalAlignment = Windows.HorizontalAlignment.Left
.Margin = New Thickness(10, 10, 0, 0)
End With
Grid.SetColumn(DetailsLB, 0)
Grid.SetRow(DetailsLB, 4)
vGrid.Children.Add(DetailsLB)
Dim DetailsTB As New MultiLineLargeTBx
With DetailsTB
.Name = "Alarm_DetailsTB"
.IsNewRecord = IsNewRecord
End With
RegisterControl(PersonalSchedule_Grid, DetailsTB)
Grid.SetColumn(DetailsTB, 1)
Grid.SetRow(DetailsTB, 4)
vGrid.Children.Add(DetailsTB)
If IsNewRecord = False Then
Dim vTime As TimeSpan = Nothing
Dim vDate As Date = Nothing
Dim vSubject As String = ""
Dim vDetails As String = ""
Dim IsAlarmSet As Boolean = False
Using vService As New Service1Client
strSQL = "Select Alarm_Date, Alarm_Time, Alarm_Subject, Alarm_Content, Alarm_Set FROM Alarm_Info WHERE Alarm_ID = " & Alarm_ID
Using DS As DataSet = vService.ReturnDataSetHAS(strSQL)
For Each Row As DataRow In DS.Tables(0).Rows
vTime = Row("Alarm_Time")
vDate = LocalDateFormat(Row("Alarm_Date"))
vSubject = ReturnText(Row("Alarm_Subject"))
vDetails = ReturnText(Row("Alarm_Content"))
Dim AlarmSet As Integer = Row("Alarm_Set")
If AlarmSet = 1 Then
IsAlarmSet = True
End If
Next
End Using
End Using
Dim TimeString As String = ReturnFormattedTime(vTime, False, True)
TimeTB.Value = TimeString
DateTB.Value = vDate
SubjectTB.Text = vSubject
DetailsTB.Text = vSubject
EnabledCB.IsChecked = IsAlarmSet
RemoveHandler EditButton.Click, AddressOf ToggleEdit_Click
RemoveHandler SV.MouseDoubleClick, AddressOf ToggleEdit_Click
RemoveHandler SaveUpdateButton.Click, AddressOf DB_Update
AddHandler EditButton.Click, AddressOf ToggleEdit_Click
AddHandler SV.MouseDoubleClick, AddressOf ToggleEdit_Click
AddHandler SaveUpdateButton.Click, AddressOf DB_Update
Else
RemoveHandler SaveUpdateButton.Click, AddressOf DB_Insert
AddHandler SaveUpdateButton.Click, AddressOf DB_Insert
End If
Return MainGrid
Catch ex As Exception
EmailError(ex)
Return Nothing
End Try
End Function
...and clicking the edit button or double clicking the ScrollViewer causes this to run
Private Sub ToggleEdit_Click(sender As Object, e As RoutedEventArgs)
Try
ToggleEdit()
Catch ex As Exception
EmailError(ex)
End Try
End Sub
Private Sub ToggleEdit()
Try
Dim SV As ScrollViewer = PersonalSchedule_Grid.FindName("Alarm_SV")
Dim DateTB As DateTBx = PersonalSchedule_Grid.FindName("Alarm_DateTB")
Dim TimeTB As TimeTBx = PersonalSchedule_Grid.FindName("Alarm_TimeTB")
Dim SubjectTB As TBx = PersonalSchedule_Grid.FindName("Alarm_SubjectTB")
Dim DetailsTB As MultiLineLargeTBx = PersonalSchedule_Grid.FindName("Alarm_DetailsTB")
Dim EnabledCB As CBx = PersonalSchedule_Grid.FindName("Alarm_EnabledCB")
Dim UpdateButton As Button = PersonalSchedule_Grid.FindName("Alarm_SaveUpdateButton")
If UpdateButton.IsEnabled = False Then
UpdateButton.IsEnabled = True
DateTB.IsNewRecord = True
TimeTB.IsNewRecord = True
SubjectTB.IsNewRecord = True
DetailsTB.IsNewRecord = True
EnabledCB.IsNewRecord = True
Else
UpdateButton.IsEnabled = False
DateTB.IsNewRecord = False
TimeTB.IsNewRecord = False
SubjectTB.IsNewRecord = False
DetailsTB.IsNewRecord = False
EnabledCB.IsNewRecord = False
End If
Catch ex As Exception
EmailError(ex)
End Try
End Sub
That should change the update button .IsEnabled to true (and the other controls .IsReadOnly) and back to false if clicked again.
It must be something very basic about WPF that I have missed for years, but running through the code in debug everything is firing as it should - it's changing the value of the control but it's not reflecting in the UI. Tried UpdateLayout and a host of other possible solutions, but...
Any pointers would be really helpful
Thanks
How could I add a new table in my access database using vb.net code.
I am supposed to write a code that when i am going to add a new file it will be having its own table in my data base.
here is my code:
Public Class Form3
Dim con As New OleDb.OleDbConnection
Dim dbprovider As String
Dim dbsource As String
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String
Dim inc As Integer
Dim intDB_ID_Selected As Integer
Dim ocmd As OleDb.OleDbCommand
Dim odatareader As OleDb.OleDbDataReader
Dim state As Integer
Dim rownumber As Integer
Dim intCurIndex As Integer
Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'SofEngdbDataSet.DentalRecords' table. You can move, or remove it, as needed.
dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbsource = "Data Source = C:\Users\AllyzaJane\Desktop\Finals\SofEngdb.mdb"
con.ConnectionString = dbprovider & dbsource
con.Open()
sql = "SELECT * FROM DentalRecords"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "SofEngdb")
tb_fname.ReadOnly = True
tb_minitial.ReadOnly = True
tb_lname.ReadOnly = True
tb_add.ReadOnly = True
tb_num.ReadOnly = True
rtb_remarks.ReadOnly = True
tb_search.ReadOnly = False
b_add.Enabled = True
b_cancel.Enabled = True
b_save.Enabled = False
b_search.Enabled = True
b_delete.Enabled = False
b_update.Enabled = False
End Sub
Private Sub b_cancel_Click(sender As System.Object, e As System.EventArgs) Handles b_cancel.Click
b_save.Enabled = False
b_add.Enabled = True
b_update.Enabled = False
b_delete.Enabled = False
b_search.Enabled = True
MsgBox("Cancelled")
tb_search.ReadOnly = False
cleartextvalue()
End Sub
Private Function DentalRecordsTableAdapter() As Object
Throw New NotImplementedException
End Function
Private Function SampledDataSet() As Object
Throw New NotImplementedException
End Function
Private Sub b_update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_update.Click
state = 0
tb_fname.ReadOnly = False
tb_fname.ReadOnly = False
tb_minitial.ReadOnly = False
tb_lname.ReadOnly = False
tb_num.ReadOnly = False
tb_add.ReadOnly = False
rtb_remarks.ReadOnly = False
tb_search.ReadOnly = True
b_add.Enabled = False
b_save.Enabled = True
b_cancel.Enabled = True
b_delete.Enabled = False
b_search.Enabled = False
b_update.Enabled = False
End Sub
Private Sub b_add_Click(sender As System.Object, e As System.EventArgs) Handles b_add.Click
state = 1
b_add.Enabled = False
b_search.Enabled = False
b_delete.Enabled = False
b_update.Enabled = False
b_save.Enabled = True
b_cancel.Enabled = True
tb_fname.ReadOnly = False
tb_minitial.ReadOnly = False
tb_lname.ReadOnly = False
tb_num.ReadOnly = False
tb_add.ReadOnly = False
rtb_remarks.ReadOnly = False
cleartextvalue()
End Sub
Private Sub b_save_Click(sender As System.Object, e As System.EventArgs) Handles b_save.Click
b_add.Enabled = True
b_save.Enabled = False
b_search.Enabled = True
' for ADD
If state = 1 Then
If tb_fname.Text = "" Or tb_minitial.Text = "" Or tb_lname.Text = "" Or tb_num.Text = "" Or tb_add.Text = "" Or rtb_remarks.Text = "" Then
MessageBox.Show("Fillup all the information needed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
Try
con.Close()
con.Open()
sql = "INSERT INTO DentalRecords (fname,minitial,lname,cnumber,address,remarks) values ('" & tb_fname.Text & "','" & tb_minitial.Text & "','" & tb_lname.Text & "','" & tb_num.Text & "','" & tb_add.Text & "','" & rtb_remarks.Text & "')"
ocmd = New OleDb.OleDbCommand(sql, con)
odatareader = ocmd.ExecuteReader()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
MessageBox.Show("Succesfully added.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
cleartextvalue()
tb_search.ReadOnly = False
End If
Else
If tb_fname.Text = "" Or tb_minitial.Text = "" Or tb_lname.Text = "" Or tb_num.Text = "" Or tb_add.Text = "" Or rtb_remarks.Text = "" Then
MessageBox.Show("Fillup all the information needed.", "Personal Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
sql = "UPDATE DentalRecords set lname = '" & tb_lname.Text & "', minitial = '" & tb_minitial.Text & "', fname = '" & tb_fname.Text & "', address = '" & tb_add.Text & "', remarks = '" & rtb_remarks.Text & "' WHERE cnumber = '" & tb_num.Text & "'"
ocmd = New OleDb.OleDbCommand(sql, con)
odatareader = ocmd.ExecuteReader()
MessageBox.Show("Successfully updated.", "Personal Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
cleartextvalue()
b_update.Enabled = False
b_save.Enabled = False
b_delete.Enabled = False
b_add.Enabled = True
b_search.Enabled = True
End If
con.Close()
End If
tb_search.ReadOnly = False
End Sub
Private Sub b_delete_Click(sender As System.Object, e As System.EventArgs) Handles b_delete.Click
Dim del As Integer
If tb_add.Text = "" Or tb_fname.Text = "" Or tb_minitial.Text = "" Or tb_lname.Text = "" Or tb_num.Text = "" Or tb_add.Text = "" Or rtb_remarks.Text = "" Then
MsgBox("No Info")
Else
Try
con.Close()
con.Open()
del = MessageBox.Show("Are you sure you want to delete this file?", "Information System", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If del = 6 Then
sql = "DELETE FROM DentalRecords WHERE fname = '" & tb_fname.Text & "' AND lname = '" & tb_lname.Text & "'AND minitial = '" & tb_minitial.Text & "'AND address = '" & tb_add.Text & "'AND cnumber = '" & tb_num.Text & "' AND remarks = '" & rtb_remarks.Text & "'"
ocmd = New OleDb.OleDbCommand(sql, con)
odatareader = ocmd.ExecuteReader()
MessageBox.Show("Data has been deleted", "Information System", MessageBoxButtons.OK, MessageBoxIcon.Information)
cleartextvalue()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Sub cleartextvalue() ' for clearing the datas after doin an operation
tb_fname.Text = ""
tb_minitial.Text = ""
tb_lname.Text = ""
tb_add.Text = ""
tb_num.Text = ""
rtb_remarks.Text = ""
tb_search.Text = ""
End Sub
Private Sub b_search_Click(sender As System.Object, e As System.EventArgs) Handles b_search.Click
If tb_search.Text = "" Then
MsgBox("Not Found")
Else
con.Close()
con.Open()
sql = "SELECT * FROM DentalRecords WHERE fname LIKE '" & tb_search.Text & "'"
ocmd = New OleDb.OleDbCommand(sql, con)
odatareader = ocmd.ExecuteReader()
If odatareader.HasRows Then
Do While odatareader.Read
tb_fname.Text = odatareader.Item(1)
tb_minitial.Text = odatareader.Item(2)
tb_lname.Text = odatareader.Item(3)
tb_num.Text = odatareader.Item(5)
tb_add.Text = odatareader.Item(4)
rtb_remarks.Text = odatareader.Item(6)
Loop
tb_fname.ReadOnly = True
tb_minitial.ReadOnly = True
tb_lname.ReadOnly = True
tb_num.ReadOnly = True
tb_add.ReadOnly = True
tb_search.ReadOnly = False
rtb_remarks.ReadOnly = True
Else
MsgBox("Not Found")
End If
b_add.Enabled = True
b_delete.Enabled = True
b_cancel.Enabled = True
b_update.Enabled = True
End If
End Sub
End Class
i want to modify this in such way that creating a table in every new file added