Question Get Data From API

HoangLuc19

Member
Joined
Nov 18, 2019
Messages
12
Programming Experience
1-3
Hello everyone, I have a function to load data into the combobox like this, but it fails to get
the data, hope you guys see how wrong the error in the above 2 lines is without getting the data:
C#:
private void getlistVendor()
{
    VendorIndexRS vendorIndexRS = apiDocument.GetVendor(new QueryRQ()).Result;
    List<VendorDetail> lstData= vendorIndexRS.Data.ToList();

    cmbVendor.DataSource =lstData;//cmbVendor.Datasoure=null
    cmbVendor.DisplayMember = "Name";
    cmbVendor.ValueMember = "Id";
}
 
Last edited by a moderator:
it fails to get
the data
You've told us nothing about this API, so we can't debug that

Does the list have any items in?

---

Tips:

If that .Result call indicates a Task, you should use async/await properly

Set the .DataSource property after setting the display and value members
 
As another hint, please don't post code without indenting. This is not the first time you've done it and it makes reading the code more difficult. I don't know how you're getting your code into your posts but you're obviously not doing it the simple and clean way. You should be copying the code from VS, which will maintain the indenting. You can hold down the Alt key to select and arbitrary block of code, enabling you to remove large wads of leading whitespace. You should then click the Code button on the toolbar and paste the code into the code editor. If the code is not indented properly, that editor can do it for you in most cases. You simply hit Ctrl+A to select all and then Shift+Tab. That's what I did to fix your code in post #1.
 
You've told us nothing about this API, so we can't debug that

Does the list have any items in?

---

Tips:

If that .Result call indicates a Task, you should use async/await properly

Set the .DataSource property after setting the display and value members
thank you. why Set the DataSource property after setting the display and value members is ok
 
thank you. why Set the DataSource property after setting the display and value members is ok
When you set the DataSource, binding is performed based on the current DisplaMember and ValueMember first. If you set DataSource, the binding is performed once then, then updated twice more as you set the other two properties. If you set DataSource last then binding gets performed once only. It will still work but you're doing pointless extra work.
 
When you set the DataSource, binding is performed based on the current DisplaMember and ValueMember first. If you set DataSource, the binding is performed once then, then updated twice more as you set the other two properties. If you set DataSource last then binding gets performed once only. It will still work but you're doing pointless extra work.
show data from cobobox is correct but when i selectvalue in combobox to insert, it can't be inserted
 
Show code that doesn't work
line 8 not find data combobox
C#:
  public async Task<DocumentDetailRS> AddDocument(DocumentDetail inputDocumentdetail)
        {
            DocumentDetailRS result= new DocumentDetailRS();
            try
            {
                GrpcChannel channel = GrpcChannel.ForAddress(url);
                var client = new Profiletracking.Document.DocumentClient(channel);
                result = client.CreateAsync(inputDocumentdetail).ResponseAsync.Result;
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
            return result;
        }
 
I don't see anything in post #9 that seems to refer at all to a ComboBox. Instead of trying to write as few words as possible, take the time to provide a FULL and CLEAR explanation of the problem, including EXACTLY what you expect to happen and EXACTLY what does happen.
 
I don't see anything in post #9 that seems to refer at all to a ComboBox. Instead of trying to write as few words as possible, take the time to provide a FULL and CLEAR explanation of the problem, including EXACTLY what you expect to happen and EXACTLY what does happen.
How to pass parameters to the api to get data from another combobox table?
 
That's not really how you do async, by the way..

Once you have declared a method as returning a Task<Xxx> and you have an async method that gets an Xxx, like GetXxxAsync() you call it with await

If you don't need to return a value, you declare the method as returning a Task, not a Task<Xxx>, and you still use await when you want to wait for an async method that gets you something
 
How to pass parameters to the api to get data from another combobox table?
I don't think this is an issue with the combobox. It think this is an issue with what you are passing in the inputDocumentdetail parameter. What fields are required to be filled in on the object when calling CreateAsync()?

What error message are you getting when an exception is thrown?
 

Latest posts

Back
Top Bottom