Exemple #1
0
 private static void GotFocusHandler(DataGrid dataGrid)
 {
     if (dataGrid.Tag != null)
     {
         var box = ExcelBehavior.GetCellItem <TextBox>(dataGrid.SelectedItem, dataGrid.CurrentColumn);
         if (box != null)
         {
             box.Text           = dataGrid.Tag.ToString();
             box.SelectionStart = 1; //move editing cursor to end of text
         }
     }
 }
Exemple #2
0
        private static void KeyUpHandler(KeyEventArgs e, DataGrid dataGrid)
        {
            //copy
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                if (e.Key == Key.C)
                {
                    var items = dataGrid.SelectedItems;
                    if (items.Count == 0)
                    {
                        return;
                    }

                    //don't let it bubble up so nothing else happens
                    e.Handled = true;

                    //JS supports clipboard, silverlight doesn't, use it
                    var clipboardData = (ScriptObject)HtmlPage.Window.GetProperty("clipboardData");
                    clipboardData.Invoke("setData", "text", ExcelBehavior.GetCellData(items, dataGrid));
                    // MessageBox.Show("Your data is now available for pasting");
                }
                else if (e.Key == Key.V)
                {
                    var    items       = dataGrid.SelectedItems;
                    object startObject = (items.Count > 0 ? items[0] : null);

                    //don't let it bubble up so nothing else happens
                    e.Handled = true;

                    //JS supports clipboard, silverlight doesn't, use it
                    var    clipboardData = (ScriptObject)HtmlPage.Window.GetProperty("clipboardData");
                    string textData      = clipboardData.Invoke("getData", "text").ToString();
                    ExcelBehavior.SetCellData(startObject, dataGrid, textData);
                }
            }
            else
            {
                //don't start editing for nav keys so a left arrow, etc. doesn't put text in a box
                if (dataGrid.Tag == null && !IsNavigationKey(e) && !dataGrid.CurrentColumn.IsReadOnly)
                {
                    bool   isShifty = ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);
                    string letter   = ((char)e.PlatformKeyCode).ToString();
                    letter = (isShifty ? letter.ToUpper() : letter.ToLower());

                    dataGrid.Tag = letter;

                    //beginedit will fire the focus event
                    //if we try to access the textbox here its text will not be set
                    dataGrid.BeginEdit();
                }
            }
        }