English 中文(简体)
是否有可能只使用键盘打1.NET DataGridView栏?
原标题:Is it possible to sort a .NET DataGridView column using only the keyboard?

在盒子中,是否可以只使用键盘打1 NET DataGridView栏?

I understand there is a SelectionMode property, but changing this merely allows me to select, using Shift+Space, an entire row or column, but this doesn t have the same effect as clicking the header with the mouse and causing a sort.

我要求的是,因为我正在处理无障碍问题,希望避免依赖这种使用。

感谢任何援助。

最佳回答

The first thing you will need to do is set the KeyPreview property to True in your form properties.

然后,在活动中,你需要为<代码>KeyDown()活动添加一个活动手。

Then add some code something like this:

public class Form1{
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);

private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        //sort column 0 descending on a  D  press
        if (e.KeyCode == Keys.D)
            dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending);

        //sort column 0 Ascending on a  U  press
        if (e.KeyCode == Keys.U)
            dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Ascending);
    }
}
问题回答

May be I m missing something, but call Sort method at the moment you receive desired Key combination.

i don t know that the column headers ever get focus (ctrl+tab/etc?), but if they could and your keyboard has a context menu button, that could work. but i don t think the headers ever get keyboard focus.

Otherwise, there may be ways to do it using standard accessability features?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签