Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disabling of Header Click in Datagrid

Posted on 2016-10-06
2
Medium Priority
?
54 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 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 14

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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