Search This Blog

Showing posts with label Windows Forms. Show all posts
Showing posts with label Windows Forms. Show all posts

Wednesday, November 5, 2014

DataGridView Windows Forms Control

Windows Forms >  DataGridView Control

You can use a DataGridView control to display data with or without an underlying data source. 
DataGridView contains cells, rows, columns, and borders.
Without specifying a data source, you can create columns and rows that contain data and add them directly to the DataGridView using the Rows and Columns properties. 






Wednesday, October 16, 2013

Determine control ToolStripItem was clicked on

C# > Controls > ContextMenuStrip


Scenario:
We have many labels on forms and one ContextMenuStrip. How can we find the control which was clicked?

Solution:

private void copyToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ToolStripItem menuItem = sender as ToolStripItem;
            if (menuItem != null)
            {
                ContextMenuStrip owner = menuItem.Owner as ContextMenuStrip;
                if (owner != null)
                {
                    Control sourceControl = owner.SourceControl;
                    Label lbl = sourceControl as Label;
                }
            }
        }





Friday, December 28, 2012

Key events not fired Windows Forms

C# > Form > KeyPreview 

KeyPreview gets or sets a value indicating whether the form will receive key events before the event is passed to the control that has focus.






Example

Key events not fired Windows Forms

Solution:

Set KeyPreview property to True