Adding data to textbox/label from data grid view (vb.net) - vb.net

i want to know the vb.net syntax to adding data to textbox or label. for example : "I Am Soldier" where the "I Am" text is from label and "Soldier" is the data that we took from data grid view
thank you

If your TextBox already contains the string "I Am" and you are trying to add another word to it, you would concatenate the strings.
TextBox.Text = TextBox.Text & " " & DataGridView.Rows(0).Cells(0).Value.ToString
Some people like to shorthand this using the &= assignment operator.
TextBox.Text &= " " & DataGridView.Rows(0).Cells(0).Value.ToString
If your TextBox is empty you simply assign that value literally.
TextBox.Text = "I Am " & DataGridView.Rows(0).Cells(0).Value.ToString

Related

How to format textbox field in Access form to show data the same as in imported file to the table

I have a textbox, which is presenting data from one field in selected recordset. This field contains comments made by user in Excel file, which is later imported to Access table. Each comment is made in separete line and in each it looks ok. Textbox present it as one line, but when I export it to Excel again it looks ok in that new excel.
I have tried changing textbox into rich text format. I have also create other textbox, in which I am able to insert comments and then it looks good.
Textbox source code:
sSql = SELECT LogID, 1Comment, 2Comment, Author
sSql = sSql & " FROM tblGeneralLog"
sSql = sSql & " WHERE LogID= " & Me.ID &
Forms![frmMain_CommentAdd]![txtboxComment2].Value = CurrentDb.OpenRecordset(sSql).Fields(2).Value
Probably, in Excel you don't have a "full new line" (CR + LF). Thus, try:
Forms![frmMain_CommentAdd]![txtboxComment2].Value = Replace(CurrentDb.OpenRecordset(sSql).Fields(2).Value, vbCr, vbCrLf)
or:
Forms![frmMain_CommentAdd]![txtboxComment2].Value = Replace(CurrentDb.OpenRecordset(sSql).Fields(2).Value, vbLf, vbCrLf)

Access 2016 - Multiple text fields - Search as you type not working

I have an Access 2016 Form with 5 text boxes labeled txtprod, txtpri, txtcnt, txtph, txtmfg. I also have a query for my table for the product name, price, count, phone and manufacturer fields.
In my forms 5 text boxes, I would like to be able to auto-search as you type and have my list auto-populate.
I followed these tutorials
https://www.youtube.com/watch?v=SJLQqwMOF08
https://www.youtube.com/watch?v=MwaRFjgwBW8
My form has a form load:
*Private Sub Form_Load()
Dim task As String
task = "SELECT * FROM pricingdata"
Me!details.RowSource = task
End Sub*
And my text box name has this event "on change"
*Private Sub txtprod_Change()
Dim task As String
task = "SELECT * FROM [pricingdata] WHERE ([Product Name] LIKE '" & Me.txtprod.Text & "');"
Me!details.RowSource = task
End Sub*
Search as I type works perfectly fine with just 1 text box. But when I add the following code to my Manufacturer text box event "on change" it doesn't work as intended.
*Private Sub txtmfg_Change()
Dim task As String
task = "SELECT * FROM [pricingdata] WHERE ([Manufacturer] LIKE '" & Me.txtmfg.Text & "');"
Me!details.RowSource = task
End Sub*
Now when I type in my Product name text box, it searched products just fine. When I start typing in my Manufacturers text box, it completely disregards anything I've put into the Product name text box and starts searching as I type only for text in the Manufacturers text box field.
How can I get this setup so all text in all 5 text box fields contribute to the search filter being applied to my list?
Something like this . . .
Private Sub ComboSelect_Change()
' You need to use String delimiters if you want to use a Text Field like:
' Me.Filter "[ATextFieldInRecordSource] = """ & Me.FilterComboBox & """"
' For a Numeric Field, use something like this:
' Me.Filter "[ANumericFieldInRecordSource] = " & Me.FilterComboBox
' Me.FilterOn = True
Me.[Customer_Query subform1].Form.Filter = "[Company_Name] Like '*" &
Replace(Me.ComboSelect.Text, "'", "''") & "*'"
Me.[Customer_Query subform1].Form.FilterOn = True
End Sub
Notice a few things:
The subform is named Customer_Query subform1’
The combobox is named ComboSelect’
Finally, the ‘like clause’ is used in combination with the wildcard character.
Like '*" & Replace(Me.ComboSelect.Text, "'", "''") & "*'"
When you type text into the combobox, the results in the subform are dynamically re-queried.

ComboBox.Text to Label.Text

The project is an alarm clock and the comboboxes select the alarm time which i want to print to label4 in the format hr:min:sec AM/PM
i need to copy the value the is selected in my comboboxes and print them into a label with the format hr:min:sec AM/PM. This is what i have:
Label4.Text = (ComboBox1.SelectedText) & ":" & (ComboBox2.SelectedText) & ":"(ComboBox3.SelectedText) & " " & (ComboBox4.SelectedText)
' the rest of the combo boxes are similar
ComboBox1.Items.Add("1")
ComboBox1.Items.Add("2")
ComboBox1.Items.Add("3")
ComboBox1.Items.Add("4")
ComboBox1.Items.Add("5")
ComboBox1.Items.Add("6")
ComboBox1.Items.Add("7")
ComboBox1.Items.Add("8")
ComboBox1.Items.Add("9")
ComboBox1.Items.Add("10")
ComboBox1.Items.Add("11")
ComboBox1.Items.Add("12")
'ComboBox1.SelectedIndex = vari1
ComboBox1.Update()
Just as you said yourself in the title, you should be using Text, not SelectedText. SelectedText is NOT the same as SelectedItem. It's the same as the similarly-named property of a TextBox, i.e. the part of the text that is highlighted. You're also missing an &, but that's not your core issue.

Datagridview filtering blank

I don't know if there's something wrong with the code, but every time I enter a value into the text box the datagridview doesn't filter, meaning it just goes blank as if it didn't find anything. can someone help me with the right code for when I insert text into the textbox, the datagridview filters for instance lets say I enter the letter "M" into the textbox, the the DGV display's all the words that start with M
heres my code
If TextBox1.TextLength > 0 Then
frmReportMenu.ProjectBindingSource.Filter = String.Format_
("[Register number] Like '&" & TextBox1.Text) & "&'"
Else
frmReportMenu.ProjectBindingSource.Filter = String.Empty
End If
I cannot find anything to properly filter the data
I think your wildcard character is wrong. Try using a * instead of the &
frmReportMenu.ProjectBindingSource.Filter = String.Format_
("[Register number] Like '*" & TextBox1.Text & "*'")

Use the actual value of String as a Formatted Value for TextBlock.Text

So basically I have this:
A WPF window with 1 Button (btn_Convert) and 2 TextBoxes (txtBox_StringValue and txtBox_Result).
In txtBox_StringValue I then paste in a formatted string value:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Then when I click btn_Convert I would like the following to happen.
Code:
Dim tempStringValue = txtBox_StringValue.Text
txtBox_Results.Text = tempStringValue
However (obviously), when I do the above the Results TextBox just displays the string again:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Instead of:
This is a Header
======================
INFO
So how do I get the value of the string and then strip the containing double-quotes so that the value when assigned acts like it was a variable value set in code, not just passing a string.
From the research I have done I am guessing that I need to use Reflection, however I am not familiar with the Reflection concept and don't know how to approach it.
Any help would be greatly appreciated!
Reflection won't help you in this case. It sounds like what you're talking about is dynamically interpreting some VB.NET source code and output the result of executing that code to another text box. In that case you need to use the Code DOM classes to dynamically build an assembly in memory and execute it.