I have a program I wrote. It opens a new window named editItem.xaml. I set the title of the program and the variables of the program. Then I check to see if DialogResult = true and if it does then I refresh the listview with some other code. I can successfully grab the data from the listview to populate the textboxes with:
ei.txtEditEffectiveDate.Text = ((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[1].ToString();
but the data is not formatted in anyway. So the date comes out as: 06/01/2014 12:00:00
I tried simply putting in the ToString("d"); to change the format but when I do I get an error:
No overload for method 'ToString' takes 1 arguments
And here is my code:
private void editEntryInstance()
{
// Open editItem.xaml
editItem ei = new editItem();
// Assign the program a title
ei.Title = "Edit Entry for Item: " + ((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[0].ToString();
// Get variables of entry
ei.txtEditItem.Text = ((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[0].ToString();
ei.txtEditEffectiveDate.Text = ((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[1].ToString();
ei.txtEditTermDate.Text = ((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[2].ToString();
ei.txtEditMoq.Text = ((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[3].ToString();
ei.txtEditSetupCost.Text = ((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[4].ToString();
if (ei.ShowDialog().Value)
{
// Refresh after editing entry
refreshInstance();
}
}
Any suggestions?
You are trying to apply ToString("d")
on a string type value. This ToString
overload is available with DateTime
type object.
You need to convert your value to a DateTime
type object and then apply ToString("d")
.
DateTime dt = Convert.ToDateTime(((System.Data.DataRowView)(listView1.SelectedItem)).Row.ItemArray[1]);
ei.txtEditEffectiveDate.Text = dt.ToString("d");
You may need DateTime.ParseExact
or DateTime.TryParseExact
for parsing string values to DateTime
if you the value contains date in custom format.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.