?
Solved

get combo box value into rich text box

Posted on 2014-12-09
10
Medium Priority
?
456 Views
Last Modified: 2014-12-09
I am trying to get the term type value from my combo box into term starts added rich text box.  In addition, I would like to clear the text boxes if the user wants to start over Calvin-code-error.PNG
0
Comment
Question by:cmed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 40489087
Not much to go on here...here's a sprinkling of magic dust:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ComboBox1.SelectedIndex <> -1 Then
            RichTextBox1.SelectionStart = RichTextBox1.TextLength
            RichTextBox1.SelectedText = "Blah blah: " & ComboBox1.SelectedItem & ", blah" & vbCrLf
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        RichTextBox1.Clear()
    End Sub

Open in new window

0
 

Author Comment

by:cmed
ID: 40489127
@ Mike Tomlinson

This is what I have so far.  I am new to vb.net, so I am a work in progress. output of code
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

Open in new window

0
 

Author Comment

by:cmed
ID: 40489140
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

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 40489188
I'd do something like:
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DTPTerm1.Format = DateTimePickerFormat.Custom
        DTPTerm1.CustomFormat = "MM/dd/yyyy"
        DTPTerm1.Value = DateTimePicker.MinimumDateTime
        btnAddTermStart.Enabled = False
    End Sub

    Private Sub Changed(sender As Object, e As EventArgs) Handles DTPTerm1.ValueChanged, COBTermType.SelectedIndexChanged
        btnAddTermStart.Enabled = ((DTPTerm1.Value <> DTPTerm1.MinDate) AndAlso (COBTermType.SelectedIndex <> -1))
    End Sub

    Private Sub btnAddTermStart_Click(sender As Object, e As EventArgs) Handles btnAddTermStart.Click
        RichTextBox1.SelectionStart = RichTextBox1.TextLength
        RichTextBox1.SelectedText = DTPTerm1.Text & " " & COBTermType.SelectedItem & vbCrLf
    End Sub

    Private Sub btnClearTermStarts_Click(sender As Object, e As EventArgs) Handles btnClearTermStarts.Click
        RichTextBox1.Clear()
    End Sub

End Class

Open in new window

0
 
LVL 34

Expert Comment

by:it_saige
ID: 40489213
Something like this:

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

Open in new window


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

Open in new window


Produces the following output -Initial state.Randomly added terms.Cleared terms and all controls set back to initial state.
-saige-
0
 

Author Closing Comment

by:cmed
ID: 40489224
@ 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.
0
 

Author Comment

by:cmed
ID: 40489253
@ 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?
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40489273
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:
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

Open in new window


-saige-
0
 

Author Comment

by:cmed
ID: 40489545
@ 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.
0
 

Author Comment

by:cmed
ID: 40489547
I have been look everywhere and trying to read information about this and cannot find anything.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question