Sort combobox alphabetically - vb.net

To begin, yes I've searched and saw the other articles regarding this and not they don't help.
I have a very simple code and I just need to sort the combo box after I populate it.
So far I have this:
'Doctor comboBox
For Each doc As Doctor In DoctorList
CBX_Doctors.Items.Add(doc.FirstName + " " + doc.LastName)
Next
I need to sort it by first name.

Use the OrderBy clause on your object. This predicate will order them by the field given.
For Each doc As Doctor In DoctorList.OrderBy(Function(o) o.FirstName)
CBX_Doctors.Items.Add(doc.FirstName + " " + doc.LastName)
Next

After you add your list, use CBX_Doctors.Sorted = True. Like this:
For Each doc As Doctor In DoctorList
CBX_Doctors.Items.Add(doc.FirstName + " " + doc.LastName)
Next
CBX_Doctors.Sorted = True

Related

Dictionary Item not populating correctly

I am out of wits on this one. I have a list like below that is available on the fly. I want to be able to create an array or a collection so that I could use it further in a loop.
Xob::SISBTXTRPR-5298
Xob::SISBTXTRPR-5326
Xob::SISBTXTRPR-5327
Xob::SISBTXTRPR-5328
Yob::SISBTXTRPR-3999
Yob::SISBTXTRPR-4000
I have tried to create a dictionary item like below but the output is not what I am expecting
While i <= iPuntedIssuesCount
If sRemovedStoriesForTaskTracker.Exists(Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName"))) Then
sRemovedStoriesForTaskTracker(Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName"))) = sRemovedStoriesForTaskTracker(Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName"))) & " + " & JSONObj("contents")("puntedIssues")(i)("key")
Else
sRemovedStoriesForTaskTracker.Add key:=Trim(JSONObj("contents")("puntedIssues")(i)("assigneeName")), Item:=JSONObj("contents")("puntedIssues")(i)("key")
End If
i = i + 1
Wend
sRemovedStoriesForTaskTracker is the dictionary item.
The output in the dictionary items that I am getting is like so:
Xob::SISBTXTRPR-5298 + SISBTXTRPR-5326 + SISBTXTRPR-5327 + SISBTXTRPR-5328.
I want the dictionary to populate like this
Xob::SISBTXTRPR-5298
Xob::SISBTXTRPR-5326
Xob::SISBTXTRPR-5327
Xob::SISBTXTRPR-5328
You don't show your source JSON, or how you're outputting the dictionary values, and your posted code doesn't seem to match what you say you want to do.
In any case, your code as-posted would benefit hugely from the use of a few variables as noted by #Damian. It's so dense it's difficult to follow.
While i <= iPuntedIssuesCount
Set d = JSONObj("contents")("puntedIssues")(i)
k = Trim(d("assigneeName"))
v = d("key")
If dictRemoved.Exists(k) Then
dictRemoved(k) = dictRemoved(k) & " + " & v
Else
dictRemoved.Add k, v
End If
i = i + 1
Wend

Contact FileAs name

I used the below document to fix existing contacts' FileAs entries. It didn't work for contacts that were company names.
https://learn.microsoft.com/en-us/office/vba/outlook/concepts/address-book/programmatically-change-the-display-format-for-all-contacts
Because the Firstname and Lastname fields were blank, it made the FileAs entry blank(" "+" "+" ").
How do I look for the blank FileAs field and set the CompanyName field as the FileAs field?
It would be something like this:
Set contactItems = items.Restrict("[MessageClass]='IPM.Contact'")
For Each itemContact In contactItems
'The underscore on the line below breaks the line into two lines.
'You need the left side of the equals for each condition in the if cant do or " "
If itemContact.Firstname = "" Or itemContact.Firstname = " " _
Or itemContact.lastname = "" or itemContact.lastname = " " Then
itemContact.FileAs = itemContact.Company
itemContact.Save
end if
Next

Dlookup reference where name of column being searched is the name of the textbox on my form

I am editing a database created by my predecessor at work. I am creating a "helper" textbox that will pull a value from a table in the same database.
Problem is, in my Dlookup, the name of the column that I am searching is also the name of the textbox on my form that contains the criteria. To change the name of my textbox, I would have to update a lot of code that I did not create. Is there a way around this?
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# = GreigeRoll#")
I expect the output to be the "GreigeWeightAvg" value from the table.
The output is:
"Syntax error (missing operator) in query expression 'GreigeRoll# = GreigeRoll#'."
Try to concatenate the value:
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "[GreigeRoll#] = " & Me![GreigeRoll#].Value & "")
or, it text:
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "[GreigeRoll#] = '" & Me![GreigeRoll#].Value & "'")
Include the fully-qualified control name in your selection criteria, e.g.:
txtgreigeweight = Application.DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# = [Forms]![YourFormName]![GreigeRoll#]")
Change YourFormName as appropriate.
At first stop using special characters in field Names...some might think that it improves readability..BUT it won't...its almost a recipe for issues.
So ... just clarify what kind of value is GreigeRoll#
If its numeric (like 1,21,21321) then you should have :
txtgreigeweight = DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# =" & [GreigeRoll#])
On the other hand is alphanumeric (like "A12", "BigGreige","1stG") then it should be :
txtgreigeweight = DLookup("[GreigeWeightAvg]", "dbo_TuftingGreigeData", "GreigeRoll# ='" & [GreigeRoll#] & "'")

Table in richtextbox

In my previous question, I posted a code that adds a table (not actually, just adds data to the richtxtbx from dgvw) in a rich text box ..The code is:
For i As Integer = 0 To dg2.Rows.Count - 2
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "-"
For j As Integer = 0 To dg2.Columns.Count - 1
Try
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbTab + dg2.Rows(i).Cells(j).Value.ToString() + vbTab
Catch ex As Exception
End Try
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLf
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "--------------------------------------------" + vbLf
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLf
Next
Next
The results look like this :
--------------------------------------------
88795446
--------------------------------------------
Mr.
--------------------------------------------
Raiyan
--------------------------------------------
rashid
--------------------------------------------
Male
--------------------------------------------
I hope you see what the problem is.. Each cell's value is being added in a new line.. How do I generate a view like this:
HEADER TEXT HEADER TEXT HEADER TEXT
------------------------------------------------
Mr. ABC 0123456789
------------------------------------------------
Mr. DEF 987654321
------------------------------------------------
Mr. GHI 898989898
I mean all cell values of a row would be in one line... The next line would be filled with dashes..... Then the next will contain the cell values of the next rows....
I know my code is correct but maybe I am having some "ARRANGING THE CODE" issue... Or is this happening because of my rich textbox size? The reason why I'm thinking so is because when I add data from a dgvw containing 2/3 columns, it works as expected.. So how to fix it or achieve the look I am looking for?
maybe this would help
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "------------------------------------------------------------------------------------------" + vbLf
For i As Integer = 0 To dg2.Rows.Count - 1
For j As Integer = 0 To dg2.Columns.Count - 1
Try
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "• " + dg2.Rows(i).Cells(j).Value.ToString() + " •"
Catch ex As Exception
End Try
Next
SendMail.bodytxt.Text = SendMail.bodytxt.Text + vbLf
SendMail.bodytxt.Text = SendMail.bodytxt.Text + "------------------------------------------------------------------------------------------" + vbLf
Next
This might even give you a better look.You must add as many "-"(dashes)as you need.Let me know if it worked
As you mentioned that when you add data to the rich text box from a datagridview that has a few columns..and then you get the result as desired..Then why not setting the WordWarp property of the Rich-text-box property to true and then add the data. Then i guess a row's cells' value wouldn't go to the next line and maybe you would be able to generate the look you want.

Set values in formula fields in crystal report from VB

I'm new in vb and crystal report so please help me from my problem. I'm assigning values using vb codes to a formula field from my crystal report. Here is my code:
Dim report As CrystalDecisions.CrystalReports.Engine.ReportDocument
report = New report_Student()
report.DataDefinition.FormulaFields("student").Text = "Slone" & Chr(13) & "Thompson"
frm_print.viewerReport.ReportSource = report
frm_print.viewerReport.RefreshReport()
frm_print.Show()
i place this in button click event. Now i have an error on running this, before it loads the crystal report from viewer this error shows:
The remaining text does not appear to be part of the formula.
Details: errorKind
Error in formula student:
'Slone
'
I guess as you have formula field (not text object) you should use formula there:
report.DataDefinition.FormulaFields("student").Text = _
ControlChars.Quote + "Slone" + ChrW(13) + "Thompson" + ControlChars.Quote
So, in result formula will contain one text literal ("Slone\nThompson").
Not tried this, but hope it should work.
If not, then probably you need to use CR inner function ChrW() for newline in next way:
report.DataDefinition.FormulaFields("student").Text = _
ControlChars.Quote + "Slone" + ControlChars.Quote + _
" + ChrW(13) + " + _
ControlChars.Quote + "Thompson" + ControlChars.Quote
So, in result two text literals ("Slone" and "Thompson") will be concatenated with result of CR inner function ChrW().
In CR formula editor it will be shown as
"Slone" + ChrW(13) + "Thompson"
But I expect 1st way should work.
You should use a report parameter instead of a formula. In case you need to modify the values inside the report use the parameter inside the formula