End Google Ads 201810 - BS.net 01 --> Hello,

I have created a datagridview using C# windows application and I am having formatting issues with the data once the datagridview has been populated. The way I have this set up is before I bind the data to the binding source I add a new row which contains combo boxes. These Como boxes are used to populate the new headers. Once the headers have been modified the data needs to be formatted to data types the system can handle. For example, the datagridview populates dates as mm/dd/yyyy 00.00.00 AM but I need to reformat this to mm/dd/yyyy. I have created a method that loops through each cell in the first row and captures the new header (which works) but when the code that is suppose to reformat the column runs, it doesn't work. the code I have to reformat the columns based on the logic used is dataGridView1.Columns[c].DefaultCellStyle.Format = "d";. However, this doesn't work. Can someone please help me? It is much appreciated. Here is what I have and if it is not enough then let me know and I can post more code.

private void button10_Click(object sender, EventArgs e)
{


if (radioButton1.Checked == true)

{

string[] newHeaders = new string[dataGridView1.ColumnCount];

int n = dataGridView1.ColumnCount;
int c = 0;

for (c = 0; c < n; c++)
{
newHeaders[c] = dataGridView1.Rows[0].Cells[c].Value.ToString();

if (newHeaders[c] == "A1ORDT")
{

dataGridView1.Columns[c].DefaultCellStyle.Format = "d";


}

}




}
else if (radioButton2.Checked == true)
{
//Add code for custom formatting
}
else
{
MessageBox.Show("Please select standard or custom formatting");
}

}

modified on Friday, April 24, 2009 5:30 PM