I am developing a vb.net winform project that includes a combobox with a list of country codes. On one form a country code is selected from this combobox and can be saved to a sql server database. On another form, a textbox shows the country code that was saved to the database from the combobox in the first form. I want to change this country code in the second form if it is wrong (i.e. update/edit the info). What I am trying to do is this, on the second form, when 'edit' is selected, the textbox with the country code is hidden and a combobox with all the country codes is shown. I want to show the country code in the hidden textbox in the now visible combobox, but at the moment it is blank when the combobox is shown. I have tried putting the info into the combobox like the textboxes straight from the database, e.g:
cbCountryCode.Text = CStr(dataTable.Rows(0).Item(2))
but this does not work. I also need to keep the country codes in the combobox as the user will need to change the country code if it's wrong. Is there a way of doing this? I have tried searching for a solution on google, but I cannot find a solution to this. I have a work around where I don't let the user update the info if the combobox is blank, but I want the country code to be already there so that the user does not have to select a country code again if it is not wrong. Any help with this problem would be greatly appreciated.
EDIT:
datatable.Rows(0).Item(2)
holds a country code, for example, Ireland (+353), United Kingdom (+44) or U.S.A. (1). This is the code I have for calling the information from the database:
sqlVisitorDetails = "SELECT * FROM visitorDetails WHERE idNumber=@idNumber"
sqlCon.Open()
sqlCmd = New SqlCommand(sqlVisitorDetails, sqlCon)
sqlCmd.Parameters.AddWithValue("@idNumber", txtIdNumber.Text)
dtVisitorDetails = loadDtVisitorDetails()
txtFirstName.Text = CStr(dtVisitorDetails.Rows(0).Item(1))
txtLastName.Text = CStr(dtVisitorDetails.Rows(0).Item(2))
txtContactNumber.Text = CStr(dtVisitorDetails.Rows(0).Item(3))
txtCountryCode.Text = CStr(dtVisitorDetails.Rows(0).Item(4))
txtAddress.Text = CStr(dtVisitorDetails.Rows(0).Item(5))
The country code (e.g. 'Ireland (+353)') is stored in dtVisitorDetails.Rows(0).Item(4) and this is put into the text box txtCountryCode. When edit is clicked on the form, the text box txtCountryCode is hidden and the combobox cbCountryCode is visible (before edit is clicked txtCountryCode is shown and cbCountryCode is hidden). I then want the country code (in this case 'Ireland (+353)') to be shown in the cbCountryCode combo box. At the moment when the combobox is shown it is blank and the user has to choose a country code again, even if it's right. I hope this makes things clearer.