private void dlButton_Click(object sender, EventArgs e) { DataGridViewColumn col1 = new DataGridViewColumn(); col1.HeaderText = "Date"; col1.Name = "Date"; col1.CellTemplate = new DataGridViewTextBoxCell(); dgv.Columns.Add(col1); bool init = true; var row = dgv.Rows[0]; List <Stock> stockList = stockLoader.LoadStocks(); foreach (var stock in stockList) { DataGridViewColumn col2 = new DataGridViewColumn(); col2.HeaderText = stock.Name; col2.Name = stock.Name; col2.CellTemplate = new DataGridViewTextBoxCell(); dgv.Columns.Add(col2); apiAddress = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + stock.Symbol + "&apikey=" + configFile.APIKEY; var json = new WebClient().DownloadString(apiAddress); var myStock = JObject.Parse(json)["Time Series (Daily)"]; int i = 0; try { foreach (JProperty prop in myStock) { if (init) { int rowIndex = dgv.Rows.Add(); row = dgv.Rows[rowIndex]; row.Cells["Date"].Value = prop.Name; } else { row = dgv.Rows[i]; } foreach (var subitem in prop) { row.Cells[stock.Name].Value = subitem["4. close"]; progBar.PerformStep(); } i++; } init = false; } catch (NullReferenceException ex) { Console.WriteLine(ex); MessageBox.Show("Sorry, API only accepts 5 requests per minute"); error = ex.Message; LogMsg(); } } }