Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C# is a pain


ghost's Avatar
0 0

I swear if this wasn't for a grade I would have trashed this…

Using a Data Grid View to add members for a Golf App. When I tried to read all members of a column into an array it bricked.

Source (Part)-

    {
      foreach (string name in dgvPlayers.Columns["Names"])
      {
      }```

Error-
```markupforeach statement cannot operate on variables of type 'System.Windows.Forms.DataGridViewColumn' because 'System.Windows.Forms.DataGridViewColumn' does not contain a public definition for 'GetEnumerator'```


ghost's Avatar
0 0

Lemur wrote: I swear if this wasn't for a grade I would have trashed this…

Using a Data Grid View to add members for a Golf App. When I tried to read all members of a column into an array it bricked.

Source (Part)-

    {
      foreach (string name in dgvPlayers.Columns["Names"])
      {
      }```

Error-
```markupforeach statement cannot operate on variables of type 'System.Windows.Forms.DataGridViewColumn' because 'System.Windows.Forms.DataGridViewColumn' does not contain a public definition for 'GetEnumerator'```

I don't know much C#, but it looks like your error is occurring because you are trying to enumerate an object that doesn't have an enumerator.

A quick look at MSDN says that .Columns[] returns a DataGridViewColumn object, which does not contain a collection of the cells. What you'll probably want to do is enumerate through the .Rows collection instead.

More info: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow.aspx