7 Replies - 689 Views - Last Post: 26 April 2014 - 09:28 AM Rate Topic: -----

#1 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 80
  • Joined: 14-December 13

Bind DatePicker control to DataGrid control (column) ?

Posted 25 April 2014 - 12:47 PM

How do I bind a DATE column in a DataGridView Control to a DatePicker control (using C#)? I already have the DataGridView control bound to a database stored procedure which takes a DATE value as a parameter and selects joining table based on the results.
Is This A Good Question/Topic? 0
  • +

Replies To: Bind DatePicker control to DataGrid control (column) ?

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3570
  • View blog
  • Posts: 11,104
  • Joined: 05-May 12

Re: Bind DatePicker control to DataGrid control (column) ?

Posted 25 April 2014 - 01:13 PM

ASP.NET or WinForms?
Was This Post Helpful? 0
  • +
  • -

#3 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 80
  • Joined: 14-December 13

Re: Bind DatePicker control to DataGrid control (column) ?

Posted 25 April 2014 - 02:02 PM

View PostSkydiver, on 25 April 2014 - 01:13 PM, said:

ASP.NET or WinForms?



WinForms
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3570
  • View blog
  • Posts: 11,104
  • Joined: 05-May 12

Re: Bind DatePicker control to DataGrid control (column) ?

Posted 25 April 2014 - 02:32 PM

You'll have to roll your own DataGridView column that implements the editing functions. This CodeProject article may give you a head start.

I really recommend abandoning WinForms and going with WPF. You'll have a lot more flexibility. And even if you have to roll your own, at least you are writing code that will have a longer shelf life than the dead end of WinForms.
Was This Post Helpful? 2
  • +
  • -

#5 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 80
  • Joined: 14-December 13

Re: Bind DatePicker control to DataGrid control (column) ?

Posted 25 April 2014 - 04:10 PM

View PostSkydiver, on 25 April 2014 - 02:32 PM, said:

You'll have to roll your own DataGridView column that implements the editing functions. This CodeProject article may give you a head start.

I really recommend abandoning WinForms and going with WPF. You'll have a lot more flexibility. And even if you have to roll your own, at least you are writing code that will have a longer shelf life than the dead end of WinForms.



That article refers to a DataGrid with DatePickers in the columns. I was thinking more along the lines of having a DatePicker control on the top of the form, and the table below will have all the data corresponding to the selected date. For example, if you select Apr 19, the table below will have 5 or so columns, one of which is date, and they are all Apr 19. Now that I think about it, we might want to leave out that column to reduce redundancy, but you know what I mean....unless there is a better way to do this..
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3464
  • View blog
  • Posts: 11,750
  • Joined: 12-December 12

Re: Bind DatePicker control to DataGrid control (column) ?

Posted 25 April 2014 - 05:16 PM

You are talking about filtering the DataGridView.

If the DGV is bound to a DataTable then you can use RowFilter. For example:
(dgvThing.DataSource as DataTable).DefaultView.RowFilter = string.Format("Field = '{0}'", textBoxFilter.Text);

If you are using a BindingSource then this has a Filter property.
Was This Post Helpful? 1
  • +
  • -

#7 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -7
  • View blog
  • Posts: 80
  • Joined: 14-December 13

Re: Bind DatePicker control to DataGrid control (column) ?

Posted 26 April 2014 - 08:25 AM

I'm not sure I quite follow. Also, how can I pass the Date value from the DatePicker control as a parameter for the stored procedure that the DataGrid refers to?

This post has been edited by andrewsw: 26 April 2014 - 09:29 AM
Reason for edit:: Removed unnecessary previous quote

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3464
  • View blog
  • Posts: 11,750
  • Joined: 12-December 12

Re: Bind DatePicker control to DataGrid control (column) ?

Posted 26 April 2014 - 09:28 AM

You will get clearer advice if you post the code that you use to populate your DataGridView.

Please note that there is no need to quote the previous post every time, there is a large Reply button further down the page.

This post has been edited by andrewsw: 26 April 2014 - 09:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1