我有一个Windows窗体应用程序,它有一大堆文本框,我用一堆字符串填充。我的问题是...代码工作正常,但似乎很浪费的打字。你能在循环函数中填充字符串中的文本框吗?将文本框与approriate字符串匹配? 这就是我所拥有的。
var client = new WebClient { Credentials = new NetworkCredential(username, password) };
var financials = client.DownloadString("https://api.intrinio.com/data_point?identifier="+conver+"&item=beta,marketcap,52_week_high,52_week_low,adj_close_price,short_interest,analyst_target_price,next_earnings_date,percent_change,yr_percent_change,implied_volatility, dividendyield,listing_exchange,sector,average_daily_volume");
var jss = client.DownloadString("https://api.intrinio.com/companies?identifier=" + conver + "");
JObject rss = JObject.Parse(jss);
JObject fin = JObject.Parse(financials);
string RRSTITLE = (string)rss["legal_name"];
string beta = (string)fin.SelectToken("data[0].value");
string marketcap = (string)fin.SelectToken("data[1].value");
string weekhigh = (string)fin.SelectToken("data[2].value");
string weeklow = (string)fin.SelectToken("data[3].value");
string adj_close = (string)fin.SelectToken("data[4].value");
string short_interest = (string)fin.SelectToken("data[5].value");
string analyst_target = (string)fin.SelectToken("data[6].value");
string earnings = (string)fin.SelectToken("data[7].value");
string percent_change = (string)fin.SelectToken("data[8].value");
string yr_percent_change = (string)fin.SelectToken("data[9].value");
string implied = (string)fin.SelectToken("data[10].value");
string divyield = (string)fin.SelectToken("data[11].value");
string exchange = (string)fin.SelectToken("data[12].value");
string sector = (string)fin.SelectToken("data[13].value");
string volume = (string)fin.SelectToken("data[14].value");
company_textbox.Text = RRSTITLE;
beta_box.Text = beta;
marketCap_box.Text = marketcap;
wekhighbox.Text = weekhigh;
weklowbox.Text = weeklow;
adjclosebox.Text = adj_close;
shortbox.Text = short_interest;
targetestbox.Text = analyst_target;
next_earnings.Text = earnings;
Close_box.Text = percent_change;
percentytd.Text = yr_percent_change;
implivolbox.Text = implied;
divyieldbox.Text = divyield;
exchangebox.Text = exchange;
sectorbox.Text = sector;
daily_Volume_text.Text = volume;
答案 0 :(得分:0)
Dictionary<string, TextBox> TextBoxLookup = new Dictionary<string, TextBox>();
Dictionary<string, string> ValueLookup = new Dictionary<string, string>();
TextBoxLookup["beta"] = beta_box;
TextBoxLookup["marketcap"] = marketCap_box;
TextBoxLookup["weekhigh"] = wekhighbox;
ValueLookup["beta"] = beta;
ValueLookup["marketcap"] = marketcap;
ValueLookup["weekhigh"] = weekhigh;
foreach(string key in TextBoxLookup.Keys)
{
TextBoxLookup[key].Text = ValueLookup[key];
}
您必须使用相同的密钥将每个教科书及其值添加到各自的词典中,并在每次需要分配时迭代分配foreach
块。
这有帮助吗?