cmed
asked on
get combo box value into rich text box
ASKER
@ Mike Tomlinson
This is what I have so far. I am new to vb.net, so I am a work in progress.
This is what I have so far. I am new to vb.net, so I am a work in progress.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DTPTerm1.Format = DateTimePickerFormat.Custom
DTPTerm1.CustomFormat = " "
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
End Sub
Private Sub COBTermType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COBTermType.SelectedIndexChanged
End Sub
Private Sub btnClearTermStarts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearTermStarts.Click
RichTextBox1.Clear()
End Sub
Private Sub btnAddTermStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTermStart.Click
If DTPTerm1.CustomFormat = CStr(DTPTerm1.CustomFormat) Then
Dim cf As String
cf = DTPTerm1.CustomFormat
RichTextBox1.SelectedText = cf
End If
If COBTermType.SelectedIndex > -1 Then
Dim sindex As Integer
sindex = COBTermType.SelectedIndex
Dim sitem As Object
sitem = COBTermType.SelectedItem
RichTextBox1.SelectedText = sitem
End If
End Sub
Private Sub DTPTerm1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DTPTerm1.ValueChanged
DTPTerm1.CustomFormat = "MM/dd/yyyy"
End Sub
ASKER
In additon, if I add selected item to the richtextbox, how can i get the selected items under each selected instead of next to each other?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DTPTerm1.Format = DateTimePickerFormat.Custom
DTPTerm1.CustomFormat = " "
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
End Sub
Private Sub COBTermType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COBTermType.SelectedIndexChanged
End Sub
Private Sub btnClearTermStarts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearTermStarts.Click
RichTextBox1.Clear()
End Sub
Private Sub btnAddTermStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTermStart.Click
If DTPTerm1.CustomFormat = CStr(DTPTerm1.CustomFormat) Then
Dim cf As String
cf = DTPTerm1.CustomFormat
RichTextBox1.SelectedText = cf
End If
If COBTermType.SelectedIndex > -1 Then
Dim sindex As Integer
sindex = COBTermType.SelectedIndex
Dim sitem As Object
sitem = COBTermType.SelectedItem
RichTextBox1.SelectedText = sitem
End If
End Sub
Private Sub DTPTerm1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DTPTerm1.ValueChanged
DTPTerm1.CustomFormat = "MM/dd/yyyy"
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Something like this:
Form1.vb -
Form1.Designer.vb -
Produces the following output -
-saige-
Form1.vb -
Public Class Form1
Private source As New BindingSource()
Private terms As List(Of Term) = New List(Of Term) From _
{ _
New Term() With {.ID = 1, .Name = "Term One", .Value = "Term1"}, _
New Term() With {.ID = 2, .Name = "Term Two", .Value = "Term2"}, _
New Term() With {.ID = 3, .Name = "Term Three", .Value = "Term3"}, _
New Term() With {.ID = 4, .Name = "Term Four", .Value = "Term4"}, _
New Term() With {.ID = 5, .Name = "Term Five", .Value = "Term5"} _
}
Private Sub OnClick(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click, Button3.Click, Button2.Click
If TypeOf sender Is Button Then
Dim btn As Button = DirectCast(sender, Button)
If btn.Equals(Button1) Then
RichTextBox1.AppendText(String.Format("{0} - [{1}]{2}", ComboBox1.SelectedValue, DateTimePicker1.Text, Environment.NewLine))
ElseIf btn.Equals(Button2) Then
' Report methods here
ElseIf btn.Equals(Button3) Then
RichTextBox1.Clear()
ComboBox1.SelectedIndex = 0
DateTimePicker1.ResetText()
End If
End If
End Sub
Private Sub OnLoad(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
source.DataSource = terms
ComboBox1.DataSource = source
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "Value"
End Sub
End Class
Public Class Term
Public Property ID() As Integer
Public Property Name() As String
Public Property Value() As String
End Class
Form1.Designer.vb -
<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.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(372, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(100, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Add Term Start"
Me.Button1.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(372, 86)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(100, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Create Report"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(372, 158)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(100, 23)
Me.Button3.TabIndex = 2
Me.Button3.Text = "Clear Term Starts"
Me.Button3.UseVisualStyleBackColor = True
'
'DateTimePicker1
'
Me.DateTimePicker1.CustomFormat = "MM/dd/yyyy"
Me.DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker1.Location = New System.Drawing.Point(51, 12)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(121, 20)
Me.DateTimePicker1.TabIndex = 3
'
'ComboBox1
'
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Location = New System.Drawing.Point(245, 12)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
Me.ComboBox1.TabIndex = 4
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(33, 13)
Me.Label1.TabIndex = 5
Me.Label1.Text = "Date:"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(178, 17)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(61, 13)
Me.Label2.TabIndex = 6
Me.Label2.Text = "Term Type:"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(12, 58)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(98, 13)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Term Starts Added:"
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(15, 75)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(309, 175)
Me.RichTextBox1.TabIndex = 8
Me.RichTextBox1.Text = ""
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(484, 262)
Me.Controls.Add(Me.RichTextBox1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
End Class
Produces the following output -
-saige-
ASKER
@ Mike Tomlinson
This works great. I will probably want to change the mimimum date time so the user will not have to go as far as 1753, but it works great.
This works great. I will probably want to change the mimimum date time so the user will not have to go as far as 1753, but it works great.
ASKER
@ it_saige
The dates would change, but the term type would only be quarters of semesters. Any suggestions.
@ Mike Tomlinson
How could I change the dates from minimum date to current date or 1/1/2015, so the user would not have to scroll as far for a date?
The dates would change, but the term type would only be quarters of semesters. Any suggestions.
@ Mike Tomlinson
How could I change the dates from minimum date to current date or 1/1/2015, so the user would not have to scroll as far for a date?
What are the specific dates for your semesters or what are the criteria that constitutes a semester. We could probably easily generate everything based on todays date and your criteria.
As for the minimum date. You only need to set the minimum date property; e.g. - using Mikes implementation:
-saige-
As for the minimum date. You only need to set the minimum date property; e.g. - using Mikes implementation:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DTPTerm1.Format = DateTimePickerFormat.Custom
DTPTerm1.CustomFormat = "MM/dd/yyyy"
' Setting the minimum date
DTPTerm1.MinDate = DateTime.Now
DTPTerm1.Value = DateTimePicker.MinimumDateTime
btnAddTermStart.Enabled = False
End Sub
-saige-
ASKER
@ it_saige
Thanks for the help. now I have to take the dates and term type from rich text box and now run the sql code and excel from another code that I created.
Thanks for the help. now I have to take the dates and term type from rich text box and now run the sql code and excel from another code that I created.
ASKER
I have been look everywhere and trying to read information about this and cannot find anything.
Open in new window