Solved

Disabling of Header Click in Datagrid

Posted on 2016-10-06
2
12 Views
Last Modified: 2016-11-28
Dear Sir/Madam,

Please be kind enough to tell me how I can disable header click after adding calendar and time using numeric updown inside datagridview.

Because both time and date clicks on the Header.

Any help would be greatly appreciated.

Kind Regards,
Indunil Sanjeewa
0
Comment
2 Comments
 
LVL 32

Accepted Solution

by:
it_saige earned 500 total points
ID: 41834034
Assuming this is in reference to: https:/Q_28974717.html

Add a check to ensure that the event row index is not -1 to the OnCellClick event; e.g. -
private void OnCellClick(object sender, DataGridViewCellEventArgs e)
{
	if (sender is DataGridView)
	{
		var grid = sender as DataGridView;
		// If the grid has rows and the cell that sent the event is not in the header row
		if (grid.Rows.Count > 0 && e.RowIndex != -1)
		{
			var dtp = default(DateTimePicker);
			var columns = new[] { "startdate", "starttime", "enddate", "endtime" };
			var column = grid.Columns[e.ColumnIndex].Name;
			if (columns.Any(x => x.Equals(column, StringComparison.OrdinalIgnoreCase)))
			{
				dtp = new DateTimePicker();
				grid.Controls.Add(dtp);
				dtp.Format = column.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1 ? DateTimePickerFormat.Time : DateTimePickerFormat.Short;
				if (dtp.Format.Equals(DateTimePickerFormat.Time))
					dtp.ShowUpDown = true;
				var rectangle = grid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
				dtp.Size = new Size(rectangle.Width, rectangle.Height);
				dtp.Location = new Point(rectangle.X, rectangle.Y);
				//dtp.CloseUp += OnCloseUp;
				dtp.Leave += OnLeave;
				dtp.Validating += OnValidating;
				dtp.Visible = true;
			}
		}
	}
}

Open in new window


-saige-
1
 
LVL 13

Expert Comment

by:frankhelk
ID: 41903877
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: it_saige (https:#a41834034)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now