i'm having problem regarding combobox in vb.net,
im trying to show & hide specific text boxes, on the base of an item when it is selected from combobox,
here is the code i'm writing, whats mistake in it?
Dim PatSearchID, PatSearchName, PatSearchCat As String
PatSearchID = txtSearchID.Text
PatSearchCat = cmbSearchPat.SelectedItem.ToString()
If PatSearchCat = "RegNo" Then
txtSearchID.Show()
txtSearchName.Hide()
End if
kindly correct what the problem is?
txtSearchName.Visible = False
30chars
instead of this (txtSearchID.Show() txtSearchName.Hide()) try to use the visible property of textbox
Related
Is there a way to get the selected text or highlighted text only from the Active Control? Active Control doesn't have .SelectedText option, so I used .Text
Example in the image.
I only highlighted "Rus" from the EnhacedTextBox.
ActiveControl.Text contains "Russia".
How do I get the SelectedText "Rus" to be set in Clipboard.SetDataObject() for copying?
Thanks a lot for your opinions and suggestions.
Do you mean you want to get selected text of a textbox ? If so,you can use TextBox.SelectedText property.
I am not sure if you are looking for this but if no, then i assume you are generating multiple textboxes from code behind/during design time ? If so, then try the following code to get the active textbox :
Private Sub GetTheText()
If Me.ActiveControl.[GetType]() = GetType(TextBox) Then
Dim textBox As TextBox = CType(Me.ActiveControl, TextBox)
Dim mytext = textbox.SelectedText
End If
End Sub
Hope this helps you
m_strGetText = Me.m_udtNavigationController.TemplateKeyAss.PrimaryTask.ActiveControl.Text.ToString()
Dim trial As EnhancedTextBox = TryCast(Me.m_udtNavigationController.TemplateKeyAss.PrimaryTask.ActiveControl, EnhancedTextBox)
Dim trial2 As String = trial.SelectedText().ToString()
Solution from #jmcilhinney.
trial2 now contains the Rus selected text. Thanks.
I want to programmatically select/highlight entire column on button click to let users know what they searched.
This is what currently happens on button click ("GO" button)
but this is what I need to happen.
I have tried these so far to no avail:
DataGridView2.SelectionMode = DataGridViewSelectionMode.FullColumnSelect
DataGridView2.Columns(2).Selected = True
Doing so gave me this error: DataGridView control's SelectionMode cannot be set to FullColumnSelect while it has a column with SortMode set to DataGridViewColumnSortMode.Automatic.
I also tried to simply select the whole column. No error, but it didn't work.
DataGridView2.Columns(2).Selected = True
Just set the Selected property of each cell in the column.
Found this thread. I modified the code like so:
Dim row As DataGridViewRow
For Each row In DataGridView2.Rows
row.Cells(1).Selected = True
Next
and placed it inside Private Sub Button1_Click
I noticed that the first cell is automatically selected. This solved that problem.
I'm working with VBA, and I'm struggling to get a combobox with two options:
First option: the textbox next to it must appear one "-", like if is supposed to be empty or disabled.
Second option: the same texbox must must be able to receive an input, like numbers.
Like: "Do you have an ID?" if no, don't fill the texbox. If yes, fill it with your number.
Thanks!
I'm assuming C# implementation but this would work essentially for any .net or WINFORMS project.
if(cbo.selectedindex = 0)
tbFoo.text = "-";
else if(cbo.selectedindex == 1)
tbFoo.text = "filltextwithID";
Check if the selectedindex of your combobox is the first or second options in the list and do your first option with the first selectedindex, else if it is the second, fill your textbox with whatever you need to fill it with(textwise).
Use your conditional if statement(naturally, I know) to check your conditions that you want your combobox to do to your textbox.
Otherwise another way to do this is with a selectedindexchanged event and do your switch statement or if statement based on which selectedindex you are talking about. 0 is the first item....all the way up to n items.
I got it! Here's the code:
Private Sub ComboBox_Change()
If ComboBox = "I don't have an ID" Then
IdTextBox.Visible = False 'Hidden
IdLabel.Visible = False
Else
IdTextBox.Visible = True 'Unhidden
IdLabel.Visible = True
End If
End Sub
I am trying to programmatically check a checkbox of a ListView (using VB & .NET 4).
The ListView lvVorschlag has been created in the designer, along with three elements. I then do the following:
Dim lviOptimal As New ListViewItem("Optimal")
lviOptimal.SubItems.Add(...) 'several SubItems are added
lvVorschlag.Items.Add(lviOptimal)
lvVorschlag.Items(0).Selected = True
All the SubItems are correctly added and the line lvVorschlag.Items(0).Selected = True does not give me an error. But nothing is checked. Any idea why?
Note: I also tried with lvVorschlag.Items("Optimal").Selected = True but it gives me an error saying that this object is Nothing. Too bad, referring by name would have been easier.
You should use the Checked property to check the item(s) you'd like:
lvVorschlag.Items(0).Checked = True
Set the focus on the item
Dim lviOptimal As New ListViewItem("Optimal")
lviOptimal.SubItems.Add(...) 'several SubItems are added
lvVorschlag.Items.Add(lviOptimal)
lvVorschlag.Items(0).focus()
lvVorschlag.Items(0).Selected = True
http://msdn.microsoft.com/en-us/library/y4x56c0b%28v=vs.100%29.aspx
Quite simply, I want to disable a textbox on another form with VBA.
I know that I can open my form like so:
DoCmd.OpenForm "frmMyForm"
I can access the value contained in a textbox on my form like so
Dim myValue As String
myValue = [Forms]![frmMyForm]![txtMyControl]
I can update the value like so:
[Forms]![frmMyForm]![txtMyControl] = "FooBar"
How do I disable the textbox (as in set the Enabled property to false)?
Thanks
I'm an idiot, it turns out all you do is this:
[Forms]![frmMyForm]![txtMyControl].Enabled = False