المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to create Unique Named Objects in a loop



C# Programming
07-01-2009, 07:10 PM
Hi, I have the following issue in C# 2, can someone point me in the correct direction please?

I need to instantiate a combobox object (one for each column in my DevExpress grid control). At design time, I have no idea how many columns the grid will have so I need to iterate through each in a loop. Each combobox will need to have a different name e.g. col.FieldName + "ComboBox". However, I can't get the syntax correct.

Current Code...

string ComboBoxName = "";
foreach (GridColumn col in view.VisibleColumns)
{
ComboBoxName = col.FieldName + "ComboBox";
RepositoryItemComboBox ComboBoxName = new RepositoryItemComboBox(); // Fails on this line as compiler says I'm attempting to redefine the ComboBoxName object //
}

Any suggestions?
Thanks