كيف يمكنني محاكاة الصحافة الرئيسية مع النسخ واللصق في infragistics Ultrawingrid؟

StackOverflow https://stackoverflow.com/questions/2158879

سؤال

أنا أستخدم infragistics UltrawingRid (الإصدار وين 9.1). السلوك الافتراضي هو السماح للمستخدم بكتابة النص في خلية. عندما يقوم أحدهم بنسخ خلايا متعددة من جدول بيانات Excel ، سيتم لصق بيانات الخلية الأولى فقط في UltrawingRid.

يمكن للمرء بسهولة تغيير السلوك لصق خلايا متعددة من خلال ضبط خلايا UltrawingRid لتكون غير قابلة للاشمئزاز cellclickaction.cellselect; ؛ لسوء الحظ عندما تفعل ذلك ، لا يمكنك كتابة البيانات في الخلايا.

لذلك حاولت تعديل هذه الإعدادات مع أحداث initializelayout و keydown و keypress.

    private void ugridQuoteSheet_InitializeLayout(object sender, InitializeLayoutEventArgs e)
    {
        e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All;
        e.Layout.Override.CellClickAction = CellClickAction.CellSelect;
    }

    //Event used to circumvent the control key from choking in
    //the KeyPress event. This doesn't work btw.
    private void ugridQuoteSheet_KeyDown(object sender, KeyEventArgs e)
    {
        UltraGrid grid = (UltraGrid)sender;

        if (e.Control == true)
        {
           e.SuppressKeyPress = true;
        }
    }

    // This event comes after the KeyDown event. I made a lame attempt to stop
    // the control button with (e.KeyChar != 22). I lifted some of this from 
    // the Infragistics post: http://forums.infragistics.com/forums/p/23690/86732.aspx#86732
    private void ugridQuoteSheet_KeyPress(object sender, KeyPressEventArgs e)
    {
        UltraGrid grid = (UltraGrid)sender;
        if ((grid != null) && (grid.ActiveCell != null) && (!grid.ActiveCell.IsInEditMode) && (e.KeyChar != 22))
        {
            grid.PerformAction(UltraGridAction.EnterEditMode);
            EditorWithText editor = (EditorWithText)grid.ActiveCell.EditorResolved;
            editor.TextBox.Text = e.KeyChar.ToString();
            editor.TextBox.SelectionStart = 1;
        }
    }

    // This puts the grid in CellSelect mode again so I won't edit text.
    private void ugridQuoteSheet_AfterCellUpdate(object sender, CellEventArgs e)
    {
        this.ugridQuoteSheet.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect;
    }

يمكنني الآن مفتاح القيم في الخلايا مرة أخرى. المشكلة هي ، عندما أضغط [Ctrl] [V] للصق ، keypresseventargs.keychar هو 22 ولا يوجد "V". يمكنك رؤية محاولتي غير المجدية للتحايل على هذه المشكلة في مندوب Ugridquoteshet_Keypress. ما هو المزيج الصحيح من معالجة الأحداث وإعداد cellclickaction للسماح لكل من ملصق النسخ والكتابة في خلية من Ultrawingrid؟

هل كانت مفيدة؟

المحلول

بعد قراءة أكثر حذراً للمنصب المذكور من قبل ( http://forums.infragistics.com/forums/p/23690/86732.aspx#86732 ) لقد تمكنت من معالجة هذه المشكلة.

يمكن التعامل مع كل هذا في حدث keypress بعد تعيين UltrawingRid.disPlayLayout.Override.CellClickAction = cellClickAction.cellselect ؛ في الحدث initializelayout بالطبع.

    private void ugridQuoteSheet_KeyPress(object sender, KeyPressEventArgs e)
    {
        UltraGrid grid = (UltraGrid)sender;

        if (!Char.IsControl(e.KeyChar) && grid != null && grid.ActiveCell != null &&
            grid.ActiveCell.EditorResolved is EditorWithText && !grid.ActiveCell.IsInEditMode)
        {
            grid.PerformAction(UltraGridAction.EnterEditMode);
            EditorWithText editor = (EditorWithText)grid.ActiveCell.EditorResolved;
            editor.TextBox.Text = e.KeyChar.ToString();
            editor.TextBox.SelectionStart = 1;
        }
    }

كنت جاهلًا بكيفية التعامل مع الصحافة المفتاح المتزامنة ، [Ctrl] [V]. char.iscontrol (E.Keychar) يقوم بالخدعة هنا.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top