//To set the dictionary for the datagrid. public static void SetKey(int index, SF_GridStatus status, string path = "") { //Checking if key has already been set. if (gridDict.ContainsKey(index)) { //Removing key. gridDict.Remove(index); } //Adding new key. gridDict.Add(index, new SF_GridItem(status, path)); }
//Instance-based public method to switch all of one type in a grid to another type. public void SwitchAll(SF_GridStatus initialStatus, SF_GridStatus newStatus) { //Finding in dictionary the integer corresponding to GridStatuses. int initStatusID = gridDict.First(x => x.Value.status == initialStatus).Key; int newStatusID = gridDict.First(x => x.Value.status == newStatus).Key; //Replacing all IDs in grid. foreach (var k in gridIndex) { for (int l = 0; l < k.Count; l++) { if (k[l] == initStatusID) { k[l] = newStatusID; } } } }
//Constructor setting public properties. public SF_GridItem(SF_GridStatus status_, string contents_ = "") { status = status_; contents = contents_; }