Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a datagridview in which 8 columns. I have to display selected cells from datagridview into textbox. I am able to display value in taxtbox from datagridview. My Problem is with date format. In datagridview and query and ms access database date format is "MM-dd-yyyy"" format but when i display datagridview cell value in textbox it is display as "ddd-MM-dd-yyyy" format. I need it should be display as "MM-dd-yyyy".

What I have tried:

<pre>I tried: dataGridView1.Columns["Processing Date"].DefaultCellStyle.Format = "MM/dd/yyyy"; dataGridView1.Columns["Due Date"].DefaultCellStyle.Format = "MM/dd/yyyy";
Posted
Updated 16-Nov-19 11:58am
Comments
phil.o 16-Nov-19 17:03pm    
Better show the code where you are assigning the Text property of the textbox then, rather than the part which concerns the datagridview.
Member 13132705 16-Nov-19 17:07pm    
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
//gets a collection that contains all the rows
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
//populate the textbox from specific value of the coordinates of column and row.
textBox5.Text = row.Cells[0].Value.ToString();
textBox6.Text = row.Cells[1].Value.ToString();
textBox7.Text = row.Cells[2].Value.ToString();
textBox8.Text = row.Cells[3].Value.ToString();
textBox9.Text = row.Cells[4].Value.ToString();
textBox10.Text = row.Cells[5].Value.ToString();
}
}
this code i am using to assign value in textbox from datagridview

Use
C#
textBox??.Text = row.Cells[?].Value.ToString("MM/dd/yyyy");
for the textbox meant to display the date.
 
Share this answer
 
Comments
Member 13132705 16-Nov-19 17:50pm    
this is not working
phil.o 16-Nov-19 18:38pm    
'not working' is not a valid issue description.
string stringtodate = ((DateTime)row.Cells[4].Value).ToString("MM-dd-yyyy");
                textBox9.Text = stringtodate;
 
Share this answer
 
Comments
Member 15426176 10-Nov-21 21:14pm    
I joined here to thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900