I have a list of items in my combo box. I need to save the selected item only into a text file. My idea is something like this.
Dim stream As New System.IO.FileStream("C:\CONFIG\PA.txt", IO.FileMode.Append, IO.FileAccess.Write)
Dim write As New System.IO.StreamWriter(stream)
Dim PA As String = (ComboBox1.SelectedItem)
write.WriteLine(PA)
But I couldn't figure out the correct way to do it. Can anyone help?
Thank you in advance.
It would be good to check for a selected item before proceeding.
Then write it like this:
If Not ComboBox1.SelectedItem Is Nothing Then
File.WriteAllText("c:\config\pa.txt", ComboBox1.Text)
End If
Related
I want to mark the checkboxes I have on a writer document, I try but don't know what's the problem.
I tried putting the cursor on range and click but it doesn't work.
Dim oAnchor 'Bookmark anchor
Dim oCursor 'Cursor at the left most range.
Dim oMarks
oMarks = oDoc.getBookmarks()
oAnchor = oMarks.getByName("Documentado").getAnchor()
oCursor = oDoc.getCurrentController().getViewCursor()
oCursor.gotoRange(oAnchor, False)
oDoc.SendKeys(MouseButtons.Left)
I tried
oDoc.getBookmarks().getByName("Documentado").getAnchor.setState(1)
which doesn't work, I read something about "com.sun.star.awt.State","com.sun.star.awt.UnoControl", "com.sun.star.awt.XCheckBox", but don't know what I need to do.
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.
Does anyone know how I set images to listview items when they contain certain text? For instance if an items' text is something with ".png" I want to give that item (or those items) an image which I've added to an imagelist.
Here is the code I use to populate the listview with folders and files:
Dim FilePath As String = "C:\"
ControlListView.Items.Clear()
Dim DirInfo() As DirectoryInfo
DirInfo = New DirectoryInfo(FilePath).GetDirectories
For Each DirInfoFolder In DirInfo
ControlListView.Items.Add(DirInfoFolder.Name)
Next
Dim FilePathFiles As New IO.DirectoryInfo(FilePath)
For Each FileInfoFolder In FilePathFiles.GetFiles
ControlListView.Items.Add(FileInfoFolder.Name)
Next
Any help would be appriciated. Thanks in advance :)
Instead of using the default ListView.Add(string), you need to construct your own ListViewItem and then add it to the ListView after setting the correct index for the image in the image list. (My VB.Net is rusty so please verify the syntax)
For Each FileInfoFolder In FilePathFiles.GetFiles
Dim lvi as New ListViewItem(FileInfoFolder.Name)
If FileInfoFolder.Name.EndsWith(".png")
lvi.ImageIndex = pngImageIndex
End If
ControlListView.Items.Add(lvi)
Next
Does someone know a code so that my program looks in the map where it is installed for rtf documents and show them in a combobox. I am making an agenda.
It can search for "VPA event -" in the title too (that is what all the event names start with). If i have the code to d that then i can use this one to read the events
Dim objreader2 As New System.IO.StreamReader(ComboBox1.Text & ".rtf")
RichTextBox2.Text = objreader2.ReadToEnd
objreader2.Close()
thanks
Here's the code you can use to load the comboBox. After that, you can use the SelectedIndexChanged event (or other events) to read the file into the rich text box. I didn't test this, but it should be pretty close.
dim ss() as string
fPath = System.Windows.Forms.Application.UserAppDataPath
' or fPath = My.Computer.FileSystem.SpecialDirectories.MyDocuments, or other directory
ss = Directory.GetFiles(fPath, "*.rtf")
ComboBox1.items.clear()
for each string s in ss
ComboBox1.Items.add(s)
next s
I want to know how to put text to a website's textbox with VB.NET.
Like when you complete a textbox and press enter.
Something like this:
Dim web as webbrowser
web.document.textbox(1).insert("text")
it would look something like this:
WebBrowser1.Document.GetElementById("login_password").SetAttribute("value", TextBox2.Text)
As giuseppe has suggested, you need to search for the element in the document and then set it's value property. for example following code logins into website by setting its userId and password textboxes and clicking the submit button.
Dim htmlDoc=WebBrowser1.Document
Dim elem_Input_UsrName As HtmlElement = htmlDoc.GetElementById("username")
Dim elem_Input_PssWrd As HtmlElement = htmlDoc.GetElementById("password")
Dim elem_Input_Submit As HtmlElement = getElementByClassName("Submit", "Input", htmlDoc)
If elem_Input_UsrName IsNot Nothing AndAlso elem_Input_PssWrd IsNot Nothing Then
elem_Input_UsrName.SetAttribute("value", "xyz#ABC.com")
elem_Input_PssWrd.SetAttribute("value", "yourpassoword")
elem_Input_Submit.InvokeMember("click")
End If
This will help 100%:
webbrowser1.document.getElementById("yourtextboxidinwebsite").innertext = textbox1.text
I get a way that if u want to receive from the website itself another way I need to receive results from the website into the text box. U can use this method.
first, make a web browser to load the page
WebBrowser1.Navigate("https://tools.keycdn.com/geo")
then this
TextBox1.Text = WebBrowser1.Document.GetElementById("geoResult").InnerText