Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
QuestionHow to upld pdf with description?? Pin
Member 1049383529-Dec-13 17:40
Member 1049383529-Dec-13 17:40 
AnswerRe: How to upld pdf with description?? Pin
Dave Kreskowiak29-Dec-13 18:05
mveDave Kreskowiak29-Dec-13 18:05 
AnswerRe: How to upld pdf with description?? Pin
ZurdoDev1-Jan-14 15:28
professionalZurdoDev1-Jan-14 15:28 
QuestionInterrupting service startup Pin
Fred283429-Dec-13 4:38
Fred283429-Dec-13 4:38 
AnswerRe: Interrupting service startup Pin
Ravi Bhavnani29-Dec-13 5:31
professionalRavi Bhavnani29-Dec-13 5:31 
AnswerRe: Interrupting service startup Pin
Dave Kreskowiak29-Dec-13 5:43
mveDave Kreskowiak29-Dec-13 5:43 
GeneralRe: Interrupting service startup Pin
Fred283429-Dec-13 7:26
Fred283429-Dec-13 7:26 
QuestionCtrl + MouseClick using PostMessage is not working for DataGridview. Pin
aks.29-Dec-13 3:03
aks.29-Dec-13 3:03 
I have a C# application with a ListView and GridView control.
I would like to simulate the mouse click in both control simultaneously.
I would like to  work this functionality even if the wind is not foreground.
So I used PostMessage to do the selection.

C#
/// <summary>
/// Select rows.
/// </summary>
/// <param name="rows">List of rows to be selected.</param>
/// <param name="selctionType">SelectionType.</param>
private void PerformSelection( List<int> rows, SelectionType selctionType )
{
   // timer1.Start();
    IntPtr wParam = MK_CONTROL;

    switch ( selctionType )
    {
        case SelectionType.Ctrl:
            wParam = MK_CONTROL;
            dataGridView1.VirtualKey = Keys.Control;
            break;
        case SelectionType.Shift:
            wParam = MK_SHIFT;
            dataGridView1.VirtualKey = Keys.Shift;
            break;
        case SelectionType.CtrlShift:
            wParam = MK_CONTROLSHIFT;
            break;
    }

    dataGridView1.Focus();

    foreach (int rowIndex in rows)
    {
        SetScrollPositionListView( rowIndex );
        NativeMethods.PostMessage( listView1.Handle, WM_LBUTTONDOWN, wParam,
                                  (IntPtr) ( ( listView1.Items[rowIndex].Position.Y << 16 ) | listView1.Items[rowIndex].Position.X ) );
        NativeMethods.PostMessage( listView1.Handle, WM_LBUTTONUP, wParam,
                                   (IntPtr) ( ( listView1.Items[rowIndex].Position.Y << 16 ) | listView1.Items[rowIndex].Position.X ) );

        SetScrollPosition(rowIndex);

        dataGridView1.Focus();
        // Get position of dgv row in dgv.
        Rectangle dgvRect = dataGridView1.GetRowDisplayRectangle(rowIndex, true);


        NativeMethods.PostMessage(dataGridView1.Handle, WM_LBUTTONDOWN, wParam, (IntPtr)((dgvRect.Top + 1 << 16) | dgvRect.Left + 1));
        NativeMethods.PostMessage(dataGridView1.Handle, WM_LBUTTONUP, wParam, (IntPtr)((dgvRect.Top + 1 << 16) | dgvRect.Left + 1));
    }
}

/// <summary>
/// Scroll to invisible rows.
/// </summary>
/// <param name="rowIndex">Index of row to be selected.</param>
private void SetScrollPositionListView( int rowIndex )
{
    listView1.EnsureVisible( rowIndex );
}

/// <summary>
/// Get the location of of row to be selected.
/// </summary>
/// <param name="rowIndex">Index of row to be selected.</param>
/// <returns>Row location.</returns>
private Point GetRowLocationListView( int rowIndex )
{
    // Scroll to row position.
    SetScrollPositionListView( rowIndex );

    // Get position of list view with respect t0 desktop.
    Point listViewlocation = listView1.PointToScreen( Point.Empty );

    Rectangle listViewRect = listView1.GetItemRect( rowIndex );

    // Calculate row co ordinate.
    int left = listViewlocation.X + listViewRect.X + ( listViewRect.Width / 2 );
    int right = listViewlocation.Y + listViewRect.Y + ( listViewRect.Height / 2 );
    return new Point( left, right );
}


For ListView the Ctrl + selection working fine. But for datagridview the only single Selection is working, the Ctrl Keydown is not working for datagridview.
When I give 1 2 3 as items to be selcected, the corresponding items selected in lisview, but for datagrid view only the last given item (3) is selected.
Could you please let me know why the above code is not working fro datagrid view.

Note: DataGridView.MulitiSelect property is True
aks


modified 30-Dec-13 3:01am.

AnswerRe: Ctrl + MouseClick using PostMessage is not working for DataGridview. Pin
Eddy Vluggen29-Dec-13 3:30
professionalEddy Vluggen29-Dec-13 3:30 
GeneralRe: Ctrl + MouseClick using PostMessage is not working for DataGridview. Pin
aks.29-Dec-13 20:36
aks.29-Dec-13 20:36 
QuestionRe: Ctrl + MouseClick using PostMessage is not working for DataGridview. Pin
Eddy Vluggen30-Dec-13 2:40
professionalEddy Vluggen30-Dec-13 2:40 
AnswerRe: Ctrl + MouseClick using PostMessage is not working for DataGridview. Pin
aks.30-Dec-13 3:39
aks.30-Dec-13 3:39 
GeneralRe: Ctrl + MouseClick using PostMessage is not working for DataGridview. Pin
Eddy Vluggen2-Jan-14 8:00
professionalEddy Vluggen2-Jan-14 8:00 
QuestionItemCommand(Repeater) not getting fired with modalpopup. Pin
Kundan Saw28-Dec-13 4:08
Kundan Saw28-Dec-13 4:08 
AnswerRe: ItemCommand(Repeater) not getting fired with modalpopup. Pin
Eddy Vluggen29-Dec-13 2:01
professionalEddy Vluggen29-Dec-13 2:01 
GeneralRe: ItemCommand(Repeater) not getting fired with modalpopup. Pin
Kundan Saw29-Dec-13 6:26
Kundan Saw29-Dec-13 6:26 
QuestionThe problem of axShockwaveFlash controls Pin
toodfu28-Dec-13 2:09
toodfu28-Dec-13 2:09 
AnswerRe: The problem of axShockwaveFlash controls Pin
Eddy Vluggen29-Dec-13 2:04
professionalEddy Vluggen29-Dec-13 2:04 
GeneralRe: The problem of axShockwaveFlash controls Pin
toodfu29-Dec-13 15:27
toodfu29-Dec-13 15:27 
GeneralRe: The problem of axShockwaveFlash controls Pin
Eddy Vluggen30-Dec-13 2:42
professionalEddy Vluggen30-Dec-13 2:42 
QuestionCannot Convert Table<T> to Table<object> Pin
talg1828-Dec-13 0:35
talg1828-Dec-13 0:35 
AnswerRe: Cannot Convert Table<T> to Table<object> Pin
OriginalGriff28-Dec-13 2:19
mveOriginalGriff28-Dec-13 2:19 
GeneralRe: Cannot Convert Table<T> to Table<object> Pin
talg1828-Dec-13 2:35
talg1828-Dec-13 2:35 
GeneralRe: Cannot Convert Table<T> to Table<object> Pin
OriginalGriff28-Dec-13 3:20
mveOriginalGriff28-Dec-13 3:20 
QuestionHow configure a virtual printer port to redirect it to a external program Pin
delphix527-Dec-13 22:47
delphix527-Dec-13 22:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.