Windows Develop Bookmark and Share   
 index > Windows Forms General > Datagrid Contextmenu Pop up
 

Datagrid Contextmenu Pop up

I am using the following code to pop up a menu:
if(e.RowIndex>=0&&e.ColumnIndex>=0&&e.Button==MouseButtons.Right)
{
dgSJ_Yarn.Rows[e.RowIndex].Selected=true;
Rectangler=dgSJ_Yarn.GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex,true);
contextMenuYarn.Show(dgSJ_Yarn,r.Left+e.X,r.Top+e.Y);
}

There are 2 rows in the grid ... the 1st row/column his highlighted when the grid opens for the first time.
When i right click on the 2nd row the full row is selected but the 1st row/column of is still selected as well.

How can i configure the grid so that is only the 2nd row is selected?

I tried changing the selectionmode to fulllrowselect but the rowheader stays on the 1st row.

thx
Kamnandi  Thursday, March 19, 2009 7:41 PM
You can set the DataGridView.MultiSelect to false. This will prevent the user from selecting multiple rows as well as achieving the desired effect with your code.

Alternatively, de-select currently selected rows by calling DataGridView.ClearSelection method before you set Selected = true.


BinaryCoder  Saturday, March 21, 2009 12:41 AM
You can set the DataGridView.MultiSelect to false. This will prevent the user from selecting multiple rows as well as achieving the desired effect with your code.

Alternatively, de-select currently selected rows by calling DataGridView.ClearSelection method before you set Selected = true.


BinaryCoder  Saturday, March 21, 2009 12:41 AM
I have set multiSelect to false but I will try the clear selection. thx
Kamnandi  Saturday, March 21, 2009 8:03 AM

You can use google to search for other answers

Custom Search

More Threads

• Docked/Anchored UserControl in Vista -- child controls don't size properly
• Printing Forms/Painting Forms to Graphics?
• GetRaiseMethod
• Form.Load????
• How to create services in vb.net.
• Application.ThreadException looses some exception information
• Behaviour of IME is strange with ActiveX controls.
• listBox
• fill Color struct from Hue saturation and brightness values
• leak in WebBrowser accessing some sites