Quote from TraderMojo:
Code:private void button1_Click(object sender, EventArgs e) { //Using an Array list to store the retrieved data. Probably better alternatives... ArrayList historicalData = new ArrayList(); //Retrieve the data from Yahoo! using the parameters specified... String yahooURL = String.Format("http://ichart.finance.yahoo.com/table.csv?s={0}&a={1}&b={2}&c={3}&d={4}&e={5}&f={6}&g=d&ignore=.csv",this.tickerSymbol.Text,this.startDateMonth.Text,this.startDateDay.Text,this.startDateYear.Text,this.endDateMonth.Text,this.endDateDay.Text,this.endDateYear.Text); try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(yahooURL); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); StreamReader reader = new StreamReader(res.GetResponseStream(), Encoding.ASCII); //Discard the first line with the headers String currentLine = reader.ReadLine(); //Read the rest of the lines while (reader.Peek() >= 0) { currentLine = reader.ReadLine(); //Parse the current line with the comma delimiter string[] values = currentLine.Split(','); //If there are 7 values in this line then assume there is valid OHLC data and it is not a dividend line if (values.Length == 7) { //Add it to our historical data historicalData.Add(new OHLC(values[0], values[1], values[2], values[3],values[4])); } } reader.Close(); } catch (Exception ee) { //Alert user that unable to retrieve historical data MessageBox.Show(ee.ToString()); } //Bind the ArrayList to the datagrid resultsGrid.DataSource = historicalData; }
I follow most of this. I have a question about the
resultsGrid.DataSource = historicalData;
Do I need to initialize resultsGrid, or include a header or something to use that object?
-uncleTom