How to Add a Method to DataColumn
- 1). Open Visual Studio 2010 by clicking on its program icon. When it loads, select "File/New/Project" and click "Visual C#/Windows Forms Application." A new Windows Form Application project is created and a blank Windows Form appears in the main editor window.
- 2). Locate the "Toolbox" panel which should be on either the left or right hand side of the Visual Studio software. The "Toolbox" contains a list of items you can add to a Windows Form. Locate the item labeled "DataGridView" and click on it.
- 3). Drag and drop the "DataGridView" item onto your Windows Form. A new "DataGridView" will appear on the form.
- 4). Click on the tiny black triangle located on the upper-right hand corner of the "DataGridView" to open a menu.
- 5). Select "Add Column" from the menu and press the "OK" button to the dialogue box that appears. The "DataGridView" now has a new column.
- 6). Double-click on the column. This creates a new method for button-press events and The Visual Studio automatically changes the view to the source code that handles this event. See this source code in the main editor window. The HTML should look something like: <br /><br /><br /><br />private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)<br /><br />{}
- 7). Print some text to the output window column during this click event by writing the following between the curly brackets of the method:<br /><br />System.Console.WriteLine("Column Clicked!");
- 8). Execute the program by pressing the green "Play" button. A Windows Form appears and it features a data grid. Click on the column and a method that prints out a message that is invoked.
Source...