I'm working on a project, and I need to display historical price. I alerady made the part to get the data from Yahoo Finance and created a form with a list view to display the data.
There is a button that allow to get the data (they are stocked in a DataTable (This part of the code works fine)) but i canno't manage to put them into the list view, I tried a lot of different methods but I always have the same output, that is the element present in the list view are the object ListViewItem
but not the value that the object contains, here is a screen shot for you to better understand :
and my code is :
private async void BtnGetData_Click(object sender, RoutedEventArgs e)
{
DataTable Histo = new DataTable();
Histo.Clear();
YahooDataList.Items.Clear();
foreach (string s in ListCol)
{
DataColumn x = new DataColumn();
x.ColumnName = s;
x.DataType = System.Type.GetType("System.String");
Histo.Columns.Add(x);
}
Symbol = "^FCHI";// Ticker.Text;
StartDate = "21/02/2021";// DD.Text;
EndDate = "21/02/2022"; //DF.Text;
//Histo = DataFromYahoo.GetData(Symbol, StartDate, EndDate);
var awaiter = await DataFromYahoo.ReceiveData(Symbol, StartDate, EndDate, Histo);
if (awaiter ==1)
{
for (int j=0; j<Histo.Rows.Count; j++)
{
DataRow dr = Histo.Rows[j];
ListViewItem item = new ListViewItem(dr["Date"].ToString());
item.SubItems.Add(dr["Open"].ToString());
item.SubItems.Add(dr["High"].ToString());
item.SubItems.Add(dr["Low"].ToString());
item.SubItems.Add(dr["Close"].ToString());
item.SubItems.Add(dr["AdjClos"].ToString());
item.SubItems.Add(dr["Volume"].ToString());
YahooDataList.Items.Add(item);
}
}
NbData.Text = Histo.Rows.Count.ToString();
Histo.Clear();
}
}
I tried to put the data into the list view following the answer of this post : here
I also tried by creating an array :
for (int j = 0; j < Histo.Rows.Count; j++)
{
string[] arr = new string[7];
arr[0] = Histo.Rows[j][0].ToString();
arr[1] = Histo.Rows[j][1].ToString();
arr[2] = Histo.Rows[j][2].ToString();
arr[3] = Histo.Rows[j][3].ToString();
arr[4] = Histo.Rows[j][4].ToString();
arr[5] = Histo.Rows[j][5].ToString();
arr[6] = Histo.Rows[j][6].ToString();
ListViewItem item = new ListViewItem(arr);
YahooDataList.Items.Add(item);
}
But the results are the same. Can someone tell me what I'm doing wrong ?
EDIT : I don't think there is nothing to do with how I created the list view but still, this is the xaml part for it :
<ListView x:Name ="YahooDataList" HorizontalAlignment="Left" Height="380" Margin="246,25,0,0" VerticalAlignment="Top" Width="525" >
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="75" />
<GridViewColumn Header="Openning" Width="75"/>
<GridViewColumn Header="High" Width="75" />
<GridViewColumn Header="Low" Width="75" />
<GridViewColumn Header="Closing" Width="75" />
<GridViewColumn Header="Clos Adj" Width="75" />
<GridViewColumn Header="Vol" Width="75" />
</GridView>
</ListView.View>
</ListView>