I'll try to give you an idea of what I am trying to do.
Let's say I have 4 columns in my datagridview/table:
+----+-------------+------------+------------+ | ID | Description | Type | Class | +----+-------------+------------+------------+ | 1 | Soft | Strawberry | Fruit | | 2 | Round | Grape | Fruit | | 3 | Sharp | Pencil | Stationary | +----+-------------+------------+------------+
This is what the final form should look like after the program is through.
Let's assume the second and last row are empty and the third row, Type, is the only one available.
I had originally attempted something like this with a switch code block like so:
switch (Type)
{
(Strawberry){
B2 = Soft;
C3 = Fruit;
}
(Grape){
etc...
}
}
Basically, we take type as the criteria argument for the other two cells. Strawberry is soft and fruit, Grape is round and fruit, etc.
I was advised to use a dictionary instead of a switch block because of the lengthy criteria's (maybe 1000 types) however, as far as I know while a dictionary can be called using a key (like Strawberry, or Grape) it will only be capable of returning one type, say, the data of Description. Moreover, I do not know how I will be able to handle writing the dictionary into datagridview format, compared to the ease of writing it with a switch statement.
Solution I came up with for future viewers:
public class DictionarySetup
{
public string theDescription { get; set; }
public string theClass { get; set; }
}
public class DictionaryInit
{
public Dictionary<int, DictionarySetup> accountRevenue = new Dictionary<int, DictionarySetup>()
{
{ 400000, new DictionarySetup {theDescription="Black", theClass="Weapon"}},
{ 400001, new DictionarySetup {theDescription="White", theClass="Mouse"}},
{ 410000, new DictionarySetup {theDescription="Opaque", theClass="Obstacle"}}
};
}
Active control:
DictionaryInit theDictionary;
private void btnFixer_Click(object sender, EventArgs e)
{
theDictionary = new DictionaryInit();
for (int rowindex = 0; rowindex < DGVMain.RowCount; rowindex++)
{
foreach (var item in theDictionary.accountRevenue)
{
int theKey = item.Key;
DictionarySetup theValues = item.Value;
DGVMain.Rows[rowindex].Cells[5].Value = theValues.theDescription;
DGVMain.Rows[rowindex].Cells[6].Value = theValues.theClass;
}
}
}