Click here to Skip to main content
14,735,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to start by saying that I am not a developer and this is my very first time writing a code to this extend of complication (at least to me). Any help/guidance would be much appreciated.

The idea of this program is to retrieve the employee user ID (or signature) from an API URL once the name has been entered.

Right now my program shows no errors, however when I press start, my combo box (labeled "Name") doesn't show any suggestion as it is intended and no information is shown in textBox 2 (labeled "user ID").

I would like to add that initially I had a text box instead of a combo box, and I was able to retrieve data correctly then. The issue occurred when I switched to the combo box. Thank you in advance.

This is my JSON string:

[{"signature":"JANDOW","firstName":"Jane","fullName":"Dow, Jane","lastName":"Dow"}]

What I have tried:

My forms code is:

TimeSheets_Try_11

{
    public partial class Form1 : Form
    {
        WebAPI WA = new WebAPI();
      

        public Form1()
        {
            InitializeComponent();
            webBrowser1.Url = new Uri(StaticStrings.UrlIora);
        }

        private void label1_Click(object sender, EventArgs e)
        {    
        }

        private void button1_Click(object sender, EventArgs e)
        {    
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

            string sgname; string projectstring;
            projectstring = comboBox1.Text.ToString();
            sgname = WA.Getsignature(projectstring);
            textBox2.Text = sgname; 
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {    
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {    
        }

        private void Form1_Load(object sender, EventArgs e)
        {    
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {                
        }
    }

}

The code for calling out the API is:
namespace TimeSheets_Try_11.Controllers
{
    class WebAPI
    {
        public string Getsignature(string name)
        {   
            var cookies = FullWebBrowserCookie.GetCookieInternal(new Uri(StaticStrings.UrlIora), false);
            WebClient wc = new WebClient();
            wc.Encoding = System.Text.Encoding.UTF8;
            wc.Headers.Add("Cookie:" + cookies);
            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            wc.UseDefaultCredentials = true;
            string uri = "";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            uri = StaticStrings.UrlIora + name + "&%24format=json&%24top=30&%24filter=status%20eq%20%27Active%27&%24count=true";
            var response = wc.DownloadString(uri);

            var status = JsonConvert.DeserializeObject<List<Employeename>>(response);
            string signame = status.Select(js => js.signature).FirstOrDefault();
            return signame;   
        }
    }
}


My code for defining the variables is:

namespace TimeSheet_Try11_Models
{ 
        public class Employeename
        {
            public string signature { get; set; }
            public string firstName { get; set; }
            public string fullName { get; set; }
            public string lastName { get; set; }
        }

        public class Root
        {
            public List<Employeename> Employeename { get; set; }
        }    
    }
Posted
Updated 21-Sep-20 23:10pm
Comments
BillWoodruff 21-Sep-20 15:53pm
   
where is the code that populates, or binds, the ComboBox ?
programmer1010101 21-Sep-20 15:57pm
   
It's in my "forms code" section
BillWoodruff 22-Sep-20 2:46am
   
that code shows setting properties of the Combobox, but does not show populating or binding.

1 solution

Do you think this
Quote:
projectstring = comboBox1.Text.ToString();
is doing what you think it's doing ?

My money would be on
projectstring = (string)comboBox1.SelectedValue;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900