///<summary>Resets tags to null and hides the given grid. ///If isSelectionMade is true, will set textBox.Text to selected item.</summary> private void CloseAndSetRecommendedContacts(ODGrid grid,bool isSelectionMade=true) { ODtextBox textBox=((ODtextBox)grid?.Tag??null); if(textBox==null) { //Done for a bug from TextBox_LostFocus where textBox was null, could be cuase by the form closing and controls being disposed? return; } textBox.Tag=null; grid.Hide(); if(isSelectionMade) { int index=textBox.Text.LastIndexOf(',');//-1 if not found. if(index==-1) {//The selected email is the first email being placed in our textbox. textBox.Text=string.Join(",",grid.SelectedGridRows.Select(x => ((string)x.Tag)).ToList()); } else{//Adding multiple emails. textBox.Text=textBox.Text.Remove(index+1,textBox.Text.Length-index-1);//Remove filter characters textBox.Text+=string.Join(",",grid.SelectedGridRows.Select(x => ((string)x.Tag)).ToList());//Replace with selected email } } textBox.Focus();//Ensures that auto complete textbox maintains focus after auto complete. textBox.SelectionStart=textBox.Text.Length;//Moves cursor to end of the text in the textbox. }
///<summary>Resets tags to null and hides the given grid. ///If isSelectionMade is true, will set textBox.Text to selected item.</summary> private void CloseAndSetRecommendedContacts(ODGrid grid, bool isSelectionMade = true) { ODtextBox textBox = (ODtextBox)grid.Tag; textBox.Tag = null; grid.Hide(); if (isSelectionMade) { int index = textBox.Text.LastIndexOf(','); //-1 if not found. if (index == -1) //The selected email is the first email being placed in our textbox. { textBox.Text = string.Join(",", grid.SelectedGridRows.Select(x => ((string)x.Tag)).ToList()); } else //Adding multiple emails. { textBox.Text = textBox.Text.Remove(index + 1, textBox.Text.Length - index - 1); //Remove filter characters textBox.Text += string.Join(",", grid.SelectedGridRows.Select(x => ((string)x.Tag)).ToList()); //Replace with selected email } } textBox.Focus(); //Ensures that auto complete textbox maintains focus after auto complete. textBox.SelectionStart = textBox.Text.Length; //Moves cursor to end of the text in the textbox. }