I have a table TKDV
in stored procedures has properties including UsageTime
of datatype datetime
.
A datagridview to display data from database, a combobox named cbSelectMonth
, a combobox named cbSelectYear
.
When selecting the "All" option from cbSelectYear
, the corresponding "all" option from cbSelectMonth
will be automatically selected and I will filter and retrieve all data from table TKDV
to be displayed in the datagridview.
When selecting a year from cbSelectYear
and a month from cbSelectMonth
, data in the database with the same month and year will be selected to be displayed in the datagridview.
When selecting a year from cbSelectYear
and "All" option from cbSelectMonth
, all data in the database for that selected year will be returned to be displayed in the datagridview.
How to do this?
I tried using array, loop, if else but it doesn't work!
1条答案
按热度按时间thigvfpy1#
in this case you would use event handlers for the comboboxes, and then refresh the datagridview based on the selected values. Here's a basic outline of how you might implement this in C#:
First, you would want to handle the selection change event for both the cbSelectYear and cbSelectMonth comboboxes.
Then you would implement the RefreshDataGridView method:
This is a simple example that might need to be adapted based on your specific needs. It assumes that the "All" option is represented as the string "All" in the comboboxes. Also, it assumes that the selectedMonth is the full name of the month, and that's why it is using DateTime.ParseExact to get the month index.