private void SearchTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (timer.IsEnabled)
            {
                //stop timer for "no matches" message immediately
                Timer_Tick(null, null);
            }

            if (e == null || e.Key == Key.Return || e.Key == Key.F3)
            {
                ShmVarDataGrid.UnselectAll();
                int i = 0;
                for (i = startIndx; i < ShmVarDataGrid.Items.Count; i++)
                {
                    SharedMemoryVariable currentVar = ShmVarDataGrid.Items[i] as SharedMemoryVariable;
                    if (currentVar.Name.ToUpper().IndexOf(searchTextBox.Text.ToUpper()) == 0)
                    {
                        ShmVarDataGrid.SelectedItem = ShmVarDataGrid.Items[i];
                        startIndx = i + 1;
                        ShmVarDataGrid.ScrollIntoView(ShmVarDataGrid.SelectedItem);
                        break;
                    }
                }

                if (i == ShmVarDataGrid.Items.Count)
                {
                    //not found
                    startIndx = 0;
                    borderFindNoMatches.Visibility = Visibility.Visible; //instead of a message box, show a hint in the search area
                    timer.Start();                                       //start timer to hide the hint after a short time
                    searchTextBox.Focus();
                }
            }
        }
        private void AddNewRow()
        {
            //MessageBox.Show("AddNewRow");       //20130730,SKK
            if (xref == null)
            {
                return;
            }

            //add a new shared memory variable at the end of the list
            xref.GetSharedMemoryManager().AddNewShmVarWithDefaultValue();

            //first set focus
            ShmVarDataGrid.Focus();

            //select the last element of the list
            ShmVarDataGrid.SelectedItem = ListOfShmVariables.Last();

            //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
            DataGridCellInfo cellInfo = new DataGridCellInfo(ShmVarDataGrid.SelectedItem, ShmVarDataGrid.Columns[0]);

            //set the cell to be the active one
            ShmVarDataGrid.CurrentCell = cellInfo;

            //scroll the item into view
            ShmVarDataGrid.ScrollIntoView(ShmVarDataGrid.SelectedItem);

            //begin the edit
            ShmVarDataGrid.BeginEdit();
        }
        private void DeleteSelectedRows()
        {
            if (xref == null)
            {
                return;
            }

            if (ShmVarDataGrid.SelectedItems.Count > 0 && MessageBox.Show("Do you really want to delete all selected variables?", "ViGET V2.0", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }

            foreach (var item in ShmVarDataGrid.SelectedItems)
            {
                SharedMemoryVariable shmVar = item as SharedMemoryVariable;
                if (shmVar.ConnectionCounter > 0)
                {
                    MessageBox.Show("At least one of the selected variables can not be deleted, because it is connected.\n\nNone of the selected variables will be deleted.", "Delete Not Possible");
                    return;
                }
            }

            int indexOfLastDeletedRow = -1;

            //remove all selected rows(shared memory variables)
            while (ShmVarDataGrid.SelectedItems.Count > 0)
            {
                indexOfLastDeletedRow = ShmVarDataGrid.SelectedIndex;
                xref.GetSharedMemoryManager().RemoveShmVar((ShmVarDataGrid.SelectedItem as SharedMemoryVariable).Name);
            }

            //first set focus
            ShmVarDataGrid.Focus();

            //set selected either the last row or the row below last deleted row
            ShmVarDataGrid.SelectedIndex = Math.Min(indexOfLastDeletedRow, ListOfShmVariables.Count - 1);

            //make the selected item visible
            if (ShmVarDataGrid.SelectedItem != null)
            {
                //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
                DataGridCellInfo cellInfo = new DataGridCellInfo(ShmVarDataGrid.SelectedItem, ShmVarDataGrid.Columns[0]);
                //set the cell to be the active one
                ShmVarDataGrid.CurrentCell = cellInfo;
                //scroll the item into view
                ShmVarDataGrid.ScrollIntoView(ShmVarDataGrid.SelectedItem);
            }
        }