0

I'm using this code when I try to add data from string arrays to DataGridView.

string fileDataField[];
count = fileDataField.Count();
count = count - 1;
for (int i = 0; i <= count; i++)
{
     DataGridViewTextBoxColumn columnDataGridTextBox = new DataGridViewTextBoxColumn();
     columnDataGridTextBox.Name = fileDataField[i];
     columnDataGridTextBox.HeaderText = fileDataField[i];
     columnDataGridTextBox.Width = 120;
     dataGridView2.Columns.Add(columnDataGridTextBox);
}
dataGridView2.Rows.Add(fileDataField);

But first row becomes header. But I don't want to load items to first and last rows.

11
  • you have to show more of your code Commented Jul 31, 2015 at 6:28
  • True, I realized it. Sorry. Commented Jul 31, 2015 at 6:31
  • 2
    edit your question, adding the code, or if you start a new one, delete this one, or flag it yourself as to be closed because of a duplicate, and then you can link to the new question, please. :-) Commented Jul 31, 2015 at 6:34
  • I re-answered the post. You can check it. Commented Jul 31, 2015 at 6:36
  • I edited your question properly. Now please delete the answer @Alptekinİpek Commented Jul 31, 2015 at 6:41

1 Answer 1

2

Dont sure what You want but the below code will not add your string array to the Header

string[] fileDataField= new string[]{"Mon","Thu","Wed","yh","Friday","sat","Sun","COOL"};
                 int  count = fileDataField.Count();
                 count = count - 1;
              for (int i = 0; i <= count; i++)
              {
                  DataGridViewTextBoxColumn columnDataGridTextBox = new DataGridViewTextBoxColumn();
                  columnDataGridTextBox.Width = 100;
                  dataGridView2.Columns.Add(columnDataGridTextBox);
                 }
                  dataGridView2.Rows.Add(fileDataField);

O/P

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.