2 回答
TA贡献1871条经验 获得超8个赞
你可以试试这个:
int selectedId;
bool res = int.TryParse(comboBox.SelectedValue.ToString(), out selectedId);
if(res)
// do something here
TA贡献1793条经验 获得超6个赞
只需使用
comboBox2.SelectedValue
编辑:对于您的 API,您可以像这样编辑代码:
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = httpClient.GetAsync("https://api.reckon.com/R1/cashbooks").Result;
string responseText = response.Content.ReadAsStringAsync().Result;`enter code here`
JArray parsedArray = JArray.Parse(responseText);
DataTable dtSource = new DataTable();
dtSource.Columns.AddRange(new DataColumn[]{new DataColumn("BookID"),new DataColumn("BookName")});
foreach (JObject parsedObject in parsedArray.Children<JObject>())
{
string BookID,BookName;
foreach (var parsedProperty in parsedObject.Properties())
{
if (parsedProperty.Name == "BookId")
{
BookID= parsedProperty.Value;
}
else if (parsedProperty.Name == "BookName")
{
BookName= parsedProperty.Value;
}
}
dtSource.Rows.Add(BookID,BookName);
}
}
comboBox2.DataSource = dtSource;
comboBox2.DisplayMember = "BookName";
comboBox2.ValueMember = "BookID";
- 2 回答
- 0 关注
- 164 浏览
添加回答
举报