|
Hi,
How about creating a custom class that inherits from ArrayList and provides a readonly property which returns a filtered list? Like this:
Public Class MyItem
Public Field1 As String
End Class
Public Class MyList
Inherits ArrayList
Public Readolny Property FilteredByField1(FilterFieldVal As String) As MyList
Get
Dim mi As MyItem
Dim rcol As New MyList
For Each mi In Me
If mi.Field1 = FilterFieldVal Then rcol.Add(mi)
Next
Return rcol
End Get
End Property
End Class
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
Hi, thanks for the advice. I was looking at using an array list to store the original data from the combobox and using that data to repopulate the combobox on the leave event. I will try this out and see how it works out. I have never used the filter functions of arraylists. Cheers
|
|
|
|
|
Hi everyone! Thanks for all of your help. I am now stuck on a key validation problem. My backspace does not delete enough of the text within a combo box for me to reset the combobox and append text etc. It will only delete this text if I hold down the backspace button. Does anyone have any suggestions? Test out the code and see if you can find anyother bugs. I also would like for the text not to completely fill the box if it is the last item until the user selects the item from the list or leaves focus on the box(would like to keep it highlighted just as if there were other items in the list). Thanks everyone!!
Imports System.Drawing.Graphics
Imports System.Drawing.Brush
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.ComponentModel.Design.Serialization
Imports System.ComponentModel
Public Class Form1
Inherits System.Windows.Forms.Form
Dim origData_cbo As New ArrayList
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
origData_cbo.Add("Please Select or Type an Item Name")
origData_cbo.Add("acada")
origData_cbo.Add("acura")
origData_cbo.Add("amy")
origData_cbo.Add("apple")
origData_cbo.Add("bananna")
origData_cbo.Add("orange")
origData_cbo.Add("pear")
origData_cbo.Add("person")
origData_cbo.Add("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
cbo1.DataSource = origData_cbo
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
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.
Friend WithEvents Uc_measurements2 As SingerProtype.uc_measurements
Friend WithEvents Uc_measurements3 As SingerProtype.uc_measurements
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Uc_measurements1 As SingerProtype.uc_measurements
Friend WithEvents cbo1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Uc_measurements2 = New SingerProtype.uc_measurements
Me.Uc_measurements3 = New SingerProtype.uc_measurements
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker
Me.Uc_measurements1 = New SingerProtype.uc_measurements
Me.cbo1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Uc_measurements2
'
Me.Uc_measurements2.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements2.displayActual = False
Me.Uc_measurements2.Location = New System.Drawing.Point(8, 248)
Me.Uc_measurements2.Name = "Uc_measurements2"
Me.Uc_measurements2.Size = New System.Drawing.Size(392, 146)
Me.Uc_measurements2.TabIndex = 1
'
'Uc_measurements3
'
Me.Uc_measurements3.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements3.displayActual = False
Me.Uc_measurements3.Location = New System.Drawing.Point(416, 8)
Me.Uc_measurements3.Name = "Uc_measurements3"
Me.Uc_measurements3.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements3.TabIndex = 2
'
'DateTimePicker1
'
Me.DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom
Me.DateTimePicker1.Location = New System.Drawing.Point(440, 120)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(192, 20)
Me.DateTimePicker1.TabIndex = 4
'
'Uc_measurements1
'
Me.Uc_measurements1.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements1.displayActual = False
Me.Uc_measurements1.Location = New System.Drawing.Point(16, 8)
Me.Uc_measurements1.Name = "Uc_measurements1"
Me.Uc_measurements1.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements1.TabIndex = 5
'
'cbo1
'
Me.cbo1.Location = New System.Drawing.Point(464, 240)
Me.cbo1.MaxDropDownItems = 10
Me.cbo1.Name = "cbo1"
Me.cbo1.Size = New System.Drawing.Size(296, 21)
Me.cbo1.TabIndex = 6
Me.cbo1.Text = "Please Select or Type an Item Name"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Location = New System.Drawing.Point(464, 224)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(304, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "AutoFill Combo Box that allows user to type extra if need be"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.ClientSize = New System.Drawing.Size(824, 454)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.cbo1)
Me.Controls.Add(Me.Uc_measurements1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Controls.Add(Me.Uc_measurements3)
Me.Controls.Add(Me.Uc_measurements2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim uc As uc_measurements = New uc_measurements
'Uc_measurements1.showActual(False)
Uc_measurements1.showActual(True)
Uc_measurements2.showActual(False)
'[Paint gradient form]
SetStyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint, True)
'[/Paint gradient form]
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'[Declare variables]
Dim formGraphics As Graphics = e.Graphics
Dim gradientMode As LinearGradientMode = LinearGradientMode.ForwardDiagonal
Dim gradientBrush As New _
LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), Color.FromArgb(236, 233, 216), Color.FromArgb(52, 101, 75), gradientMode)
formGraphics.FillRectangle(gradientBrush, ClientRectangle)
'[/Declare variables]
End Sub
'Function used to handle the on key up event
Private Sub cbo1_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles cbo1.KeyUp
AutoCompleteCombo_keyUp(sender, e)
End Sub
'Function used to display first matching item as user types letters into the combo box
Public Sub AutoCompleteCombo_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim cbo As ComboBox = sender 'takes the combo box calling the function and sets it to a local combobox
'Allow select keys without Autocompleting
Select Case e.KeyCode
Case Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down, Keys.Back
If e.KeyValue = Keys.Back Then
append(sender, e)
End If
Exit Sub
End Select
append(sender, e)
End Sub
'Append possible text that may follow
Private Sub append(ByVal sender As Object, ByVal e As EventArgs)
Dim cbo As ComboBox = sender
Dim foundIndex As Integer = -1 'takes the users typed text and if found in a datasource, stores the index
Dim foundArrLst As New ArrayList
Dim foundText As String = ""
Dim typedText As String = "" 'takes the text typed into the combobox by the users and stores it into a local string variable
Dim appendText As String = ""
Dim posCursor As Integer = cbo.SelectionStart 'takes the position of the cursor when the function is called
typedText = cbo.Text
foundIndex = cbo.FindString(typedText)
If posCursor <> 0 Then
cbo.DroppedDown() = True
If foundIndex >= 0 Then
'Use the ListControl.GetItemText to resolve the Name in case the Combo was Data bound
'Get the Item from the list (Return Type depends if Datasource was bound or List Created)
foundText = cbo.GetItemText(cbo.Items.Item(foundIndex))
'Append then found text to the typed text to preserve case
appendText = foundText.Substring(typedText.Length)
cbo.Text = typedText + appendText
reduceList(foundIndex, foundArrLst, cbo, typedText)
cbo.SelectionStart = typedText.Length
cbo.SelectionLength = appendText.Length
End If
Else
resetComboBox(sender, e)
End If
End Sub
'Reduce the List of Possibilities
Private Sub reduceList(ByVal foundIndex As Integer, ByRef foundArray As ArrayList, _
ByRef cbo As ComboBox, ByVal typedText As String)
'If we found the Typed Text in the list then Autocomplete
If foundIndex >= 0 Then
Dim item As String
For Each item In cbo.Items
' try a partial string match, looking at the first few letters of each name
' can also use If Mid(i, 1, Len(sTypedText)) = sTypedText Then
' if there's a match, stick the name in the results list
If Microsoft.VisualBasic.Left(item, typedText.Length).ToUpper = typedText.ToUpper Then
foundArray.Add(item)
End If
Next
End If
cbo.DataSource = foundArray
adjustWidth_dropDown(cbo)
cbo.DroppedDown = True
End Sub
'Calls a function to adjust the width of the combo box
Private Sub cbo1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles cbo1.DropDown
adjustWidth_dropDown(cbo1)
End Sub
'Function used to handle longer text strings that don't fit in a sized combo box
Public Sub adjustWidth_dropDown(ByRef cbo As ComboBox)
Dim i As Integer
Dim tempLength As Integer = 0
Dim tempString As String = ""
Dim largestWidth As Integer = 0
Dim newWidth As Integer
Dim g As Graphics = cbo.CreateGraphics()
Dim tempFont As Font = cbo1.Font
Dim vertScrollWidth As Integer = (cbo.Items.Count > cbo.MaxDropDownItems) 'check to see if we need a scroll bar
For i = 0 To cbo.Items.Count - 1
newWidth = g.MeasureString(cbo.Items.Item(i), tempFont).Width + vertScrollWidth
If (largestWidth < newWidth) Then
largestWidth = newWidth
End If
cbo.DropDownWidth = largestWidth
Next
End Sub
'Function called when the focus leaves the combobox to reset the values in the drop down list
Private Sub cbo1_FocusLeavePrivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.Leave
resetComboBox(sender, e)
End Sub
'Function used to reset the values in the combo box drop down list to the original when a user leaves the box
Private Sub resetComboBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cbo As ComboBox = sender
Dim prevSelected As String
prevSelected = cbo.Text.ToString()
cbo.DataSource = origData_cbo
If (prevSelected <> "") Then
cbo.SelectedItem = cbo.Items.Item(cbo.FindString(prevSelected))
cbo.Text = prevSelected
End If
End Sub
Private Sub cbo1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.GotFocus
'cbo1.DroppedDown() = True
End Sub
'Not Working
Private Sub AutoCompleteComboBox1_Submit(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo1.Enter
Dim wComboValue As String = "(New Item)"
If Not IsNothing(cbo1.SelectedValue) Then
wComboValue = cbo1.SelectedValue
End If
'goes in the append text to get rid of wildcards
' Remove *, ' e % from the string
'If Strings.Right(cbo.Text, 1) = "*" Or Strings.Right(cbo.Text, 1) = "'" Or Strings.Right(cbo.Text, 1) = "%" Then
'cbo.Text = cbo.Text.Substring(0, Len(cbo.Text) - 1)
'cbo.SelectionStart = cbo.Text.Length
'Exit Sub
'End If
'If cbo.Text.IndexOf("*") <> -1 Or cbo.Text.IndexOf("'") <> -1 Or cbo.Text.IndexOf("%") <> -1 Then
'cbo.Text = cbo.Text.Replace("*", "").Replace("'", "").Replace("%", "")
'End If
End Sub
End Class
|
|
|
|
|
Hi everyone, this code handles backspaces, populates the combobox..filters out the stuff that doesn't match the users input, but I am having a problem when I try to type strings that match a single word, but with more chars. I would like to be able to continue typing and displaying nothing in the combobox type thing. But, when I type the extra chars, the combobox forces me back to the start position of the combobox. Does anyone have any idea what is going on? Thank you.
Imports System.Drawing.Graphics
Imports System.Drawing.Brush
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.ComponentModel.Design.Serialization
Imports System.ComponentModel
Public Class Form1
Inherits System.Windows.Forms.Form
Dim origData_cbo As New ArrayList
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
origData_cbo.Add("Please Select or Type an Item Name")
origData_cbo.Add("acada")
origData_cbo.Add("acura")
origData_cbo.Add("amy")
origData_cbo.Add("apple")
origData_cbo.Add("bananna")
origData_cbo.Add("orange")
origData_cbo.Add("pear")
origData_cbo.Add("person")
origData_cbo.Add("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")
cbo1.DataSource = origData_cbo
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
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.
Friend WithEvents Uc_measurements2 As SingerProtype.uc_measurements
Friend WithEvents Uc_measurements3 As SingerProtype.uc_measurements
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Uc_measurements1 As SingerProtype.uc_measurements
Friend WithEvents cbo1 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Uc_measurements2 = New SingerProtype.uc_measurements
Me.Uc_measurements3 = New SingerProtype.uc_measurements
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker
Me.Uc_measurements1 = New SingerProtype.uc_measurements
Me.cbo1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Uc_measurements2
'
Me.Uc_measurements2.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements2.displayActual = False
Me.Uc_measurements2.Location = New System.Drawing.Point(8, 248)
Me.Uc_measurements2.Name = "Uc_measurements2"
Me.Uc_measurements2.Size = New System.Drawing.Size(392, 146)
Me.Uc_measurements2.TabIndex = 1
'
'Uc_measurements3
'
Me.Uc_measurements3.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements3.displayActual = False
Me.Uc_measurements3.Location = New System.Drawing.Point(416, 8)
Me.Uc_measurements3.Name = "Uc_measurements3"
Me.Uc_measurements3.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements3.TabIndex = 2
'
'DateTimePicker1
'
Me.DateTimePicker1.Location = New System.Drawing.Point(440, 240)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.Size = New System.Drawing.Size(192, 20)
Me.DateTimePicker1.TabIndex = 4
'
'Uc_measurements1
'
Me.Uc_measurements1.BackColor = System.Drawing.Color.DarkGray
Me.Uc_measurements1.displayActual = False
Me.Uc_measurements1.Location = New System.Drawing.Point(16, 8)
Me.Uc_measurements1.Name = "Uc_measurements1"
Me.Uc_measurements1.Size = New System.Drawing.Size(392, 152)
Me.Uc_measurements1.TabIndex = 5
'
'cbo1
'
Me.cbo1.Location = New System.Drawing.Point(408, 336)
Me.cbo1.MaxDropDownItems = 10
Me.cbo1.Name = "cbo1"
Me.cbo1.Size = New System.Drawing.Size(296, 21)
Me.cbo1.TabIndex = 6
Me.cbo1.Text = "Please Select or Type an Item Name"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.Transparent
Me.Label1.Location = New System.Drawing.Point(408, 320)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(304, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "AutoFill Combo Box that allows user to type extra if need be"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ControlDarkDark
Me.ClientSize = New System.Drawing.Size(824, 454)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.cbo1)
Me.Controls.Add(Me.Uc_measurements1)
Me.Controls.Add(Me.DateTimePicker1)
Me.Controls.Add(Me.Uc_measurements3)
Me.Controls.Add(Me.Uc_measurements2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Dim uc As uc_measurements = New uc_measurements
'Uc_measurements1.showActual(False)
Uc_measurements1.showActual(True)
Uc_measurements2.showActual(False)
'[Paint gradient form]
SetStyle(ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint, True)
'[/Paint gradient form]
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'[Declare variables]
Dim formGraphics As Graphics = e.Graphics
Dim gradientMode As LinearGradientMode = LinearGradientMode.ForwardDiagonal
Dim gradientBrush As New _
LinearGradientBrush(New Rectangle(0, 0, Me.Width, Me.Height), Color.FromArgb(236, 233, 216), Color.FromArgb(52, 101, 75), gradientMode)
formGraphics.FillRectangle(gradientBrush, ClientRectangle)
'[/Declare variables]
End Sub
'Function used to handle the on key up event
Private Sub cbo1_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles cbo1.KeyUp
AutoCompleteCombo_keyUp(sender, e)
cbo1.DroppedDown() = True
End Sub
'Function used to display first matching item as user types letters into the combo box
Public Sub AutoCompleteCombo_keyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
Dim cbo As ComboBox = sender 'takes the combo box calling the function and sets it to a local combobox
'Allow select keys without Autocompleting
Select Case e.KeyCode
Case Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down, Keys.Back
If e.KeyValue = Keys.Back Then
append(sender, e, "1")
End If
Exit Sub
End Select
append(sender, e, "0")
End Sub
'Append possible text that may follow
Private Sub append(ByVal sender As Object, ByVal e As EventArgs, ByVal minus As Integer)
Dim cbo As ComboBox = sender
Dim foundIndex As Integer = -1 'takes the users typed text and if found in a datasource, stores the index
Dim foundArrLst As New ArrayList
Dim foundText As String = ""
Dim typedText As String = "" 'takes the text typed into the combobox by the users and stores it into a local string variable
Dim appendText As String = ""
Dim posCursor As Integer = cbo.SelectionStart 'takes the position of the cursor when the function is called
If (cbo.Text.Length > 0) Then
typedText = cbo.Text.Substring(0, cbo.Text.Length - minus)
End If
resetComboBox(sender, e)
foundIndex = cbo.FindString(typedText)
If posCursor <> 0 Then
If foundIndex >= 0 Then
'Use the ListControl.GetItemText to resolve the Name in case the Combo was Data bound
'Get the Item from the list (Return Type depends if Datasource was bound or List Created)
foundText = cbo.GetItemText(cbo.Items.Item(foundIndex))
'Append then found text to the typed text to preserve case
appendText = foundText.Substring(typedText.Length)
cbo.Text = typedText + appendText
reduceList(foundIndex, foundArrLst, cbo, typedText)
cbo.SelectionStart = typedText.Length
cbo.SelectionLength = appendText.Length
End If
Else
resetComboBox(sender, e)
End If
End Sub
'Reduce the List of Possibilities
Private Sub reduceList(ByVal foundIndex As Integer, ByRef foundArray As ArrayList, _
ByRef cbo As ComboBox, ByVal typedText As String)
'If we found the Typed Text in the list then Autocomplete
If foundIndex >= 0 Then
Dim i As String
For Each i In cbo.Items
' try a partial string match, looking at the first few letters of each name
If Mid(i, 1, Len(typedText)) = typedText Then
' if there's a match, stick the name in the results list
foundArray.Add(i)
End If
Next
End If
'If we found the Typed Text in the list then Autocomplete
'If foundIndex >= 0 Then
'Dim item As String
'For Each item In cbo.Items
' try a partial string match, looking at the first few letters of each name
' can also use If Mid(i, 1, Len(sTypedText)) = sTypedText Then
' if there's a match, stick the name in the results list
'If Microsoft.VisualBasic.Left(item, typedText.Length).ToUpper = typedText.ToUpper Then
'foundArray.Add(item)
'End If
'Next
'End If
cbo.DataSource = foundArray
adjustWidth_dropDown(cbo)
cbo.DroppedDown = True
End Sub
'Calls a function to adjust the width of the combo box
Private Sub cbo1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles cbo1.DropDown
adjustWidth_dropDown(cbo1)
End Sub
'Function called when the focus leaves the combobox to reset the values in the drop down list
Private Sub cbo1_FocusLeavePrivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.Leave
resetComboBox(sender, e)
End Sub
'Function used to reset the values in the combo box drop down list to the original when a user leaves the box
Private Sub resetComboBox(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cbo As ComboBox = sender
Dim prevSelected As String
prevSelected = cbo.Text.ToString()
cbo.DataSource = origData_cbo
If cbo.FindString(prevSelected) >= 0 Then
cbo.SelectedItem = cbo.Items.Item(cbo.FindString(prevSelected))
cbo.Text = prevSelected
End If
End Sub
'Function used to handle longer text strings that don't fit in a sized combo box
Public Sub adjustWidth_dropDown(ByRef cbo As ComboBox)
Dim i As Integer
Dim tempLength As Integer = 0
Dim tempString As String = ""
Dim largestWidth As Integer = 0
Dim newWidth As Integer
Dim g As Graphics = cbo.CreateGraphics()
Dim tempFont As Font = cbo1.Font
Dim vertScrollWidth As Integer = (cbo.Items.Count > cbo.MaxDropDownItems) 'check to see if we need a scroll bar
For i = 0 To cbo.Items.Count - 1
newWidth = g.MeasureString(cbo.Items.Item(i), tempFont).Width + vertScrollWidth
If (largestWidth < newWidth) Then
largestWidth = newWidth
End If
cbo.DropDownWidth = largestWidth
Next
End Sub
Private Sub cbo1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbo1.GotFocus
cbo1.DroppedDown() = True
End Sub
'Not Working
Private Sub AutoCompleteComboBox1_Submit(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo1.Enter
Dim wComboValue As String = "(New Item)"
If Not IsNothing(cbo1.SelectedValue) Then
wComboValue = cbo1.SelectedValue
End If
'goes in the append text to get rid of wildcards
' Remove *, ' e % from the string
'If Strings.Right(cbo.Text, 1) = "*" Or Strings.Right(cbo.Text, 1) = "'" Or Strings.Right(cbo.Text, 1) = "%" Then
'cbo.Text = cbo.Text.Substring(0, Len(cbo.Text) - 1)
'cbo.SelectionStart = cbo.Text.Length
'Exit Sub
'End If
'If cbo.Text.IndexOf("*") <> -1 Or cbo.Text.IndexOf("'") <> -1 Or cbo.Text.IndexOf("%") <> -1 Then
'cbo.Text = cbo.Text.Replace("*", "").Replace("'", "").Replace("%", "")
'End If
End Sub
End Class
|
|
|
|
|
The idea behined this is to create a report writer, we have found or did got solution on Crystal report when we view the report as may times the different window will shown
which we could control from in send of VB Program...
that is why we started write a new program were we can customise the report according our level. as RichtexBox gives the fecility to change fonts etc .. we got the solution to add the Image but we can't control the Image as in terms of size and postion
Please advice
|
|
|
|
|
You COULD use the RichTextBox control, but it doesn't offer the flexibility of EXACT placement and scaling control of images that you want. Your best bet is either Crystal Reports, or custom writing your own code for drawing each page exactly the way you want it using GDI+, not a RichTextBox.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The idea behined this is to create a report writer, we have found or did got solution on Crystal report when we view the report as may times the different window will shown
which we could control from in send of VB Program...
that is why we started write a new program were we can customise the report according our level. as RichtexBox gives the fecility to change fonts etc .. we got the solution to add the Image but we can't control the Image as in terms of size and postion
Please advice
|
|
|
|
|
Hi,
I am trying to get my new mail application for a schoole project to recognize URLs dragged onto it as the actual files the URLs are pointing to, .i.e, if I drag a URL onto it, it should attach the file, not just give the path to the file. At the moment, I am just managing to get it to drop the text of the URL. Any advice or pointers to useful code will be much appreciated.
Thanks
|
|
|
|
|
Wow, not easy. You app has to, when a URL is dropped on it, handle the drag and drop code the same way you are now. But when you get the URL text that points to the file, you must download the file and then your code mush attach the file that was downloaded.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi everybody
is there any way to keep an exe file into vb 6.0 so that when ever i close the form the application should also close (i.e the exe file should act as a child form in main form)
thank you all
|
|
|
|
|
This doesn't make any sense at all...
Are you asking if it is possible to run an external application and make its windows child windows of your application? Where the windows are actually MDIChildren in your application?
If this is what your asking, then no it's not. The application will put up it's own windows that are not managable from outside that application.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hello
the problem i'm having is that i cant get the value i wanted from a .txt file
value in .txt file
123.445
value after call .readline
123445
the value in the .txt is a double value but when i call it to the application it become integer.
did i type the wrong coding?
the declaration and coding is as below
Dim num1 As Double
Dim sr As IO.StreamReader = IO.File.OpenText("info.txt")
Do While (sr.Peek <> -1)
num1 = CDbl(sr.ReadLine)
Loop
Text1.Text = num1
i even try almost everything i know
but the output is still 123445 and not 123.445
please help me
thank you
Gary the amatuer
|
|
|
|
|
You don't use CDbl for this. Use Double.Parse instead. CDbl is for converting between number types, not string to number:
Imports System.IO
.
.
.
Dim num1 As Double
Dim sr As StreamReader = File.OpenText("info.txt")
Do While (sr <> -1)
num1 = Double.Parse(sr.ReadLine())
Loop
Text1.Text = num1.ToString()
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hello dave
im sorry but the result is still the same
im still getting 12345 instead of 123.45
i double check everything and the value in the notepad is 123.45
i try using label instead of textbox but the same thing is shown
i try changing the value in notepad to 345,232.45 and this error comes out
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
but if i change it to 123.455,67 it just show me 123455,67
is the problem coming from the notepad?
i change most of the coding as you recommended
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim name, display As String
Dim total, amount, charges As Double
Dim num1 As Double
Dim sr As StreamReader = File.OpenText("info.txt")
Do While (sr.Peek <> -1)
num1 = Double.Parse(sr.ReadLine())
Loop
Text1.Text = num1.ToString()
Label2.Text = num1.ToString()
i'm so confuse on this problem cause i try reading book and it say that this two method should provide me with the answer i was looking for but it seem like it is not
please help me
thank you and sorry for the trouble
Gary the amatuer
|
|
|
|
|
This problem has nothing to do with Notepad what-so-ever.
These are the possibilities:
1) This is not the code your running.
2) The code is not opening the file you think it is.
3) The info.txt file has more to it than you're telling me.
When I tested this code, the only thing in my text file was a single line, "123.45", without the quotes. This code is GARANTEED to return the correct results:
Dim num1 As Double
Dim sr As StreamReader = File.OpenText("D:\test.txt")
num1 = Double.Parse(sr.ReadLine())
TextBox1.Text = num1.ToString()
They way your code is setup, your reading the ENTIRE file first, then returning the last value that was read. Your code can only work if the only thing on each line is a single decimal number without any punctuation except for one period.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks dave for your help
i think i know what is causing all this problem that i have been having so far
i took most of my application build on my PC to my friends PC to test and it all work prefectly as i expected.but when i try at my own PC anouynomous error pop out.
i cant even do the coding below while my friends PC can
formatnumber(1234,2)
formatcurrency(1234,0)
i think this happen cause some of the file needed is missing
the solution that you provide me work well in my friends PC after i send my application to him.
the "123.45" value is able to be shown and calculated as i expected
you might think that im pulling your leg but it is really the truth
and im sorry to cause you such trouble
i have to delete my vb.net program and then reinstall it again and this time i hope no problem will occur to my future programs
again thanks for your help
Gary
|
|
|
|
|
GaryKoh wrote:
formatnumber(1234,2)formatcurrency(1234,0)
?????? What's with the comma's in the place where the decimal point is supposed to go? Is this the format of the numbers in the file? If so, the Parse method will not work unless you go into the Regional and Language Settings control panel and change the Country to the one where this data is coming from. For instance, in Germany, the number 1,000,000.00 (US-English) is represented by 1.000.000,00 The decimals and commas are interchanged.
What I'm trying to get at is the Parse method is locale sensitive. It will parse numbers based on the settings found in the Regional and Language Settings control panel.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hahaha
thanks dave
the problem i have is just the Regional and Language Setting in my computer
it is set to my country setting
but now i have set it to US-English everything is working well
and now i understand it perfectly the parse method is always base on each computer regional setting
thanks
you really help me
thank you
Gary
|
|
|
|
|
I'm am working on a database in MS Access 2000. I have imported data from a text file.
Their are now two fields that imported in to a table:
Title and Subtitle
I want to make a macro or query (anything that is automatic) to combine the two values (Title and Subtitle) into one (MyTitle) for all the records (about 2,953). Thank you in advance.
-Peace
|
|
|
|
|
Not sure if this is what you are looking for but.
UPDATE yourtable SET main.combinedfield = [yourtable]![Title] & " " & [YourTable]![SubTitle];
|
|
|
|
|
Where do I put this code? I am trying to get it to update the field (if it needs to be updated) when the form is open. Or if I can make a macro that would do it.
|
|
|
|
|
I am not sure of your situation but I would suggest using the Acces macro builder and use the formrun or similar event to fire the import. The code is all VBA or VBscript so you may even find some code on Google that will do it for you. If you are importing this file every time the app opens you may need to work out a different strategy since this could eventually lead to errors. Good luck and I hope it helps.
|
|
|
|
|
I'm new to windows programming so please don't laugh.
I have a visual basic .NET program that i've created. I can install it on PCs and it runs fine.
I want to be able to put it on a server that is on our local network, and I want users to be able to run the exe from through their network neighborhood (over the network). My most desirable option is that the program need not be installed locally to be able to run from the network. (Of course .NET framework would have to be installed locally)
As it is now, if I copy the exe to some place on the network and try to run it from there I recieve a unhandled exception error right away, even if the user has write permissions to that directory.
Where do I need to go next with this program to be able to do this? Remote Services???
|
|
|
|
|
You should be able to copy the executable to a share and run it with no problems as long as the required runtimes are installed on the local machine.
If you're getting an exception on the server, then your best bet would be to either install a dev environment on the server to allow you to step through the code and found it where it craps out.
Although, I'd recommend (it help find out what's causing it instead of possibly just fixing it) using the process of elimination in your code by commented certain parts until it starts working and take it from there.
Jeremy Falcon
|
|
|
|
|
Running a .NET program from a shared drive is not the same as running it locally, because of code-access security. Local programs are more "trusted" than remote ones, so depending on what your app is trying to do, it may get a permissions exceptions.
Couple different ways to tackle this:
* modify the .NET policies for your particular application, on each PC (by using the control panel .NET wizards)
* change your app to only do things that it is allowed to in that particular environment. For example, if you are saving files to a local drive, maybe try using isolated storage instead.
* run the app locally
my blog
|
|
|
|
|