populating combo box on run time - vb.net

I got two combo box on the system a Category and Sub Category
my concept must be when i choose COM OR PRT on cmbCategory,
cmbSubCategory will automatically display the corresponding subcategory for the category chosen
Private Sub cmbCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCategory.SelectedIndexChanged
If cmbCategory.Text = "COM" Then
cmbSubCategory.Items = "SU, MON"
End If
End Sub
my code returns error
Property Items is Read Only

Items is a collection so to put things into it you need to add them to the collection rather than direct assignment.
If SU and MON are meant to appear as separate items in the combo box then you could do something similar to:
Private Sub cmbCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCategory.SelectedIndexChanged
If cmbCategory.Text = "COM" Then
cmbSubCategory.Items.Clear()
cmbSubCategory.Items.Add("SU")
cmbSubCategory.Items.Add("MON")
End If
End Sub
If SU, MON is meant to appear as a single item then you could do:
Private Sub cmbCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCategory.SelectedIndexChanged
If cmbCategory.Text = "COM" Then
cmbSubCategory.Items.Clear()
cmbSubCategory.Items.Add("SU, MON")
End If
End Sub
Note that we use Clear to remove items from the combo box/ensure it is empty before populating it with the right options.
PS. I noticed that one of the tags for this question is "SQL", but from what I've read I don't think that this question has a SQL component to it...

Related

variable object name error

I have the following:
a listbox called ListBox1 with a couple of random values in it
a couple of rich textboxs called Rit11 up to Rit 154
a button
When I click a rich textbox, I want to set the a variable to the number that the box is called. After this I select a value from the listbox, and when I press the button, I want this value to move to the selected textbox, and be removed from the listview. I made the following code, but it gives an error.
Private Sub Rit12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rit12.Click
SelBox = "12"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim BoxName
BoxName = ("Rit" & SelBox)
Me.Controls(BoxName).Text = ListBox1.SelectedItem
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
It worked fine, till I tried using the variable name. This rule seems to give the problem:
Me.Controls(BoxName).Text = ListBox1.SelectedItem

Drag and drop Text Box to List Box

I'm working on a VB.net(2015) code that would allow me to drag and drop from a text box to a list box.
I've set up the code below, and set the allow drop in the list box to true.
I’m able to drag the text to the list box, but it doesn’t appear in the list box.
Looking at the code below I’m not sure what piece I’ve left out, are there any recommendations or suggestions on what can be done?
Public Class PotluckParty
Private Sub enterFoodTextBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles enterFoodTextBox.MouseDown
enterFoodTextBox.DoDragDrop(enterFoodTextBox.Text, DragDropEffects.Move)
End Sub
Private Sub SaladListBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SaladListBox.DragDrop
SaladListBox.Text &= e.Data.GetData(DataFormats.Text).ToString
enterFoodTextBox.Text = ""
End Sub
Private Sub SaladListBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SaladListBox.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Move
End If
End Sub

Add a checkbox to allow the labels to be updated whenever the input text changes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am very new to programming language and am in my first Programming class at my university. For a project we are creating a VERY simple project where the user enters words and the program puts them together. It's day one stuff I know but I'm trying to go for the extra credit and "Add a check box to allow the labels to be updated whenever the input text changes".
I have a program that when you type in two separate words in separate text boxes it displays each word individually and then also the two words combined at the bottom. Our professor wants my to add an check box option at the bottom that when clicked with make it so when the users types the two words they display automatically without clicking the display button.
I know this is easy stuff, but any help would be much appreciated.
Thank you for your help.
Public Class form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblLeft.Click
End Sub
Private Sub lbl2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblRight.Click
End Sub
Private Sub txtBoxLeft_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBoxLeft.TextChanged
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim strTxtBoxLeft As String
strTxtBoxLeft = txtBoxLeft.Text
Dim strTxtBoxRight As String
strTxtBoxRight = txtBoxRight.Text
lblLeft.Text = strTxtBoxLeft
lblRight.Text = strTxtBoxRight
lblCombo.Text = strTxtBoxLeft & " " & strTxtBoxRight
End Sub
Private Sub chkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkbox.CheckedChanged
If chkbox.CheckState = False Then
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Try this:
Public Class Form1
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
combineText()
End Sub
Private Sub chkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkbox.CheckedChanged
If chkbox.CheckState = False Then
lblCombo.Text = ""
End If
End Sub
Private Sub txtBox_TextChanged(sender As Object, e As EventArgs) Handles txtBoxRight.TextChanged, txtBoxLeft.TextChanged
If chkbox.CheckState Then
combineText()
End If
End Sub
Private Sub combineText()
lblCombo.Text = txtBoxLeft.Text & " " & txtBoxRight.Text
End Sub
End Class
Note: I have consolidated your logic down to just grab the text from the text boxes themselves. There is also one handler that handles text changing in either of the text boxes. Finally, there is a single method that handles combining the values of the two text boxes together, either via the text changed event if the check box is checked or if the user clicks the update button. Also, if the user unchecks the check box, then it will clear the results. Then when the user clicks update it will display the combined text again.

Making a link from GridView in VB.NET 2012 (Windows Form)

I have project to develop an application for employees and schedule management on my campus. My plan is to develop with VB.NET and use SQL Server for the database.
How can I use a grid view to make a link going to another window? The window will show all information by schedule.
You are looking for DataGridViewLinkColumn. Also check this link.
Once CellContentClick event fires, you can create another form and pass desired values to that form to display details and show them up.
You can also use DataGridViewButtonColumn too.
EDIT:
I assume that I have two forms frmMaster and frmDetails. DataGridView lies on frmMaster and user keeps record ID in TAG property of first cell.
then, FrmMaster code would be:
Private Sub frmMaster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Added a LinkColumn from code (you can do it at design time too)
DataGridView1.Columns.Add(New DataGridViewLinkColumn() With {.Text = "Show details"})
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim detail As New frmDetail() ' create an instance of detail form
detail.ID = DataGridView1.Rows(e.RowIndex).Cells(0).Tag'set property of detail form
detail.ShowDialog() ' Show form
End Sub
and frmdetail code would be:
Private _Id As String
Public Property ID() As String
Get
Return _Id
End Get
Set(ByVal value As String)
_Id = value
End Set
End Property
Private Sub frmDetail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData(_Id)
End Sub
Sub LoadData(ByVal _id As Integer)
'' use '_id' variable to extract data from dtaabse via query
End Sub

How can i search using a Text box and Listbox in vb.Net?

give me code, in which i can enter a word in a textbox and a listbox appear with a item that has same string in which i enter in a textbox.
Please Help me...
I found the following via Google, which sound like the type of things you want to do:
Autosearch ListBox in VB.NET
(WinForms)
Search Listboxes as You Type
(WinForms or is this VB6?)
Searching for items in a ListBox
(WPF)
Using # 1, here is some code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
List1.Items.Add("Computer")
List1.Items.Add("Screen")
List1.Items.Add("Modem")
List1.Items.Add("Printer")
List1.Items.Add("Scanner")
List1.Items.Add("Sound Blaster")
End Sub
Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.TextChanged
Dim i As Integer = List1.FindString(Text1.Text)
List1.SelectedIndex = i
If Text1.Text = "" Then
List1.SelectedIndex = -1
End If
End Sub
Think pseudocode, you can do this.
Grab the text from the textbox.
Set a pointer / counter to the listbox and loop through each item until the end of the list. If the textbox value has the same value as the listboxitem.text then you've found a match exit the for loop.
Add this code to texboxchange
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListBox1.SelectedIndex = ListBox1.FindString(TextBox1.Text.Trim)
End Sub