C#--datagridview Adding DateTimePicker Time Controls

Source: Internet
Author: User

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace test{          Public partial class form1:form    {        datetimepicker  DTP = new DateTimePicker () ; //instantiation of a DateTimePicker control          rectangle _rectangle;        Public Form1 ()         {            InitializeComponent ();      & nbsp     DATAGRIDVIEW1.CONTROLS.ADD (DTP); //Add Time controls to datagridview            DTP . Visible = false; //Do not display             DTP. format = datetimepickerformat.custom; //Set Date format,2017-11-11            DTP. TextChanged + = new EventHandler (dtp_textchange); Adding events to a Time control dtp_textchange       } /************* time control when selecting time ****************/private void Dtp_textchange (object sender, EventArgs e) { DataGridView1.CurrentCell.Value = DTP.  Text.tostring (); When the time control selects the time, assigns the time content to the cell in which it is located}/**************** cell is clicked to determine if the column of the time control is placed *******************/        private void datagridview1_ CellClick (object sender, DataGridViewCellEventArgs e)         {          &NBSP ; if (E.columnindex = = 0)             {                _rectangle = Datagridview1.getcelldisplayrectangle (E.columnindex, E.rowindex, true); Get the location and size of your cell                 DTP. size = new Size (_rectangle.width, _rectangle.height); Assign the cell size to the time control                 DTP. Location = new Point (_rectangle.x, _rectangle.y); Assign cell locations to time controls                 DTP. Visible = true; //Display controls            }            ELSE&NBSP ;               DTP. Visible = false;       }/*********** when the width of a column changes, the time control is first hidden, otherwise the time control cannot be changed ***********/private void datagridview1_columnwidthchanged When the height of the cell changes. Object sender, DataGridViewColumnEventArgs e) {DTP.                    Visible = false; }/*********** the scrollbar is scrolled, the cell position changes and the time control is hidden, otherwise the time control position does not move ********/private void Datagridview1_scroll (object sender, Scroll EventArgs e) {DTP.        Visible = false; }    }}

C#--datagridview Adding DateTimePicker Time Controls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.