Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - presenze mensili datagridview
Forum - C# / VB.NET - presenze mensili datagridview

Avatar
antoniobar (Normal User)
Newbie


Messaggi: 18
Iscritto: 09/09/2012

Segnala al moderatore
Postato alle 19:18
Giovedì, 29/10/2015
salve, ho fatto alcuni programmi con vb.net ma sono sempre un principiante!!! vorrei creare per il mio lavoro un programma per le presenze mensili !! la mia intenzione è quella di popolare una datagridview con il mese corrente ma non so come fare o addirittura un calendario!! grazie se mi postate un codice o mi dite come arrivarci
grazie

PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6378
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 19:30
Giovedì, 29/10/2015
Che "codice" si può postare per un progetto simile?

Dovresti, prima di tutto, progettare un DB per memorizzare i dati ...


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti (uno dei padri fondatori del moderno Calcolo delle probabilità) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
antoniobar (Normal User)
Newbie


Messaggi: 18
Iscritto: 09/09/2012

Segnala al moderatore
Postato alle 19:51
Giovedì, 29/10/2015
si quello lo so fare ma come faccio a creare datagridview stile calendario??

PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 0:28
Venerdì, 30/10/2015
Testo quotato

Postato originariamente da antoniobar:

salve, ho fatto alcuni programmi con vb.net ma sono sempre un principiante!!! vorrei creare per il mio lavoro un programma per le presenze mensili !! la mia intenzione è quella di popolare una datagridview con il mese corrente ma non so come fare o addirittura un calendario!! grazie se mi postate un codice o mi dite come arrivarci
grazie



If ok Then GOTO Avanza else GOTO Inizia

PM Quote
Avatar
antoniobar (Normal User)
Newbie


Messaggi: 18
Iscritto: 09/09/2012

Segnala al moderatore
Postato alle 15:20
Martedì, 03/11/2015
ho visto il codice ma la classe come faccio a farla avviare con il form?
lo so ma sono ad un livello bassisimo!!!

PM Quote
Avatar
Ultimo (Member)
Guru


Messaggi: 877
Iscritto: 22/05/2010

Segnala al moderatore
Postato alle 17:06
Martedì, 03/11/2015
Testo quotato

Postato originariamente da antoniobar:

ho visto il codice ma la classe come faccio a farla avviare con il form?
lo so ma sono ad un livello bassisimo!!!




Codice sorgente - presumibilmente VB.NET

  1. Imports System
  2. Imports System.Windows.Forms
  3. Public Class Form1
  4.  
  5.  
  6.     Public Class CalendarColumn
  7.         Inherits DataGridViewColumn
  8.  
  9.         Public Sub New()
  10.             MyBase.New(New CalendarCell())
  11.         End Sub
  12.  
  13.         Public Overrides Property CellTemplate() As DataGridViewCell
  14.             Get
  15.                 Return MyBase.CellTemplate
  16.             End Get
  17.             Set(ByVal value As DataGridViewCell)
  18.  
  19.                 ' Ensure that the cell used for the template is a CalendarCell.
  20.                 If (value IsNot Nothing) AndAlso _
  21.                     Not value.GetType().IsAssignableFrom(GetType(CalendarCell)) _
  22.                     Then
  23.                     Throw New InvalidCastException("Must be a CalendarCell")
  24.                 End If
  25.                 MyBase.CellTemplate = value
  26.  
  27.             End Set
  28.         End Property
  29.  
  30.     End Class
  31.  
  32.     Public Class CalendarCell
  33.         Inherits DataGridViewTextBoxCell
  34.  
  35.         Public Sub New()
  36.             ' Use the short date format.
  37.             Me.Style.Format = "d"
  38.         End Sub
  39.  
  40.         Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
  41.             ByVal initialFormattedValue As Object, _
  42.             ByVal dataGridViewCellStyle As DataGridViewCellStyle)
  43.  
  44.             ' Set the value of the editing control to the current cell value.
  45.             MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
  46.                 dataGridViewCellStyle)
  47.  
  48.             Dim ctl As CalendarEditingControl = _
  49.                 CType(DataGridView.EditingControl, CalendarEditingControl)
  50.  
  51.             ' Use the default row value when Value property is null.
  52.             If (Me.Value Is Nothing) Then
  53.                 ctl.Value = CType(Me.DefaultNewRowValue, DateTime)
  54.             Else
  55.                 ctl.Value = CType(Me.Value, DateTime)
  56.             End If
  57.         End Sub
  58.  
  59.         Public Overrides ReadOnly Property EditType() As Type
  60.             Get
  61.                 ' Return the type of the editing control that CalendarCell uses.
  62.                 Return GetType(CalendarEditingControl)
  63.             End Get
  64.         End Property
  65.  
  66.         Public Overrides ReadOnly Property ValueType() As Type
  67.             Get
  68.                 ' Return the type of the value that CalendarCell contains.
  69.                 Return GetType(DateTime)
  70.             End Get
  71.         End Property
  72.  
  73.         Public Overrides ReadOnly Property DefaultNewRowValue() As Object
  74.             Get
  75.                 ' Use the current date and time as the default value.
  76.                 Return DateTime.Now
  77.             End Get
  78.         End Property
  79.  
  80.     End Class
  81.  
  82.     Class CalendarEditingControl
  83.         Inherits DateTimePicker
  84.         Implements IDataGridViewEditingControl
  85.  
  86.         Private dataGridViewControl As DataGridView
  87.         Private valueIsChanged As Boolean = False
  88.         Private rowIndexNum As Integer
  89.  
  90.         Public Sub New()
  91.             Me.Format = DateTimePickerFormat.Short
  92.         End Sub
  93.  
  94.         Public Property EditingControlFormattedValue() As Object _
  95.             Implements IDataGridViewEditingControl.EditingControlFormattedValue
  96.  
  97.             Get
  98.                 Return Me.Value.ToShortDateString()
  99.             End Get
  100.  
  101.             Set(ByVal value As Object)
  102.                 Try
  103.                     ' This will throw an exception of the string is
  104.                     ' null, empty, or not in the format of a date.
  105.                     Me.Value = DateTime.Parse(CStr(value))
  106.                 Catch
  107.                     ' In the case of an exception, just use the default
  108.                     ' value so we're not left with a null value.
  109.                     Me.Value = DateTime.Now
  110.                 End Try
  111.             End Set
  112.  
  113.         End Property
  114.  
  115.         Public Function GetEditingControlFormattedValue(ByVal context _
  116.             As DataGridViewDataErrorContexts) As Object _
  117.             Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
  118.  
  119.             Return Me.Value.ToShortDateString()
  120.  
  121.         End Function
  122.  
  123.         Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As  _
  124.             DataGridViewCellStyle) _
  125.             Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
  126.  
  127.             Me.Font = dataGridViewCellStyle.Font
  128.             Me.CalendarForeColor = dataGridViewCellStyle.ForeColor
  129.             Me.CalendarMonthBackground = dataGridViewCellStyle.BackColor
  130.  
  131.         End Sub
  132.  
  133.         Public Property EditingControlRowIndex() As Integer _
  134.             Implements IDataGridViewEditingControl.EditingControlRowIndex
  135.  
  136.             Get
  137.                 Return rowIndexNum
  138.             End Get
  139.             Set(ByVal value As Integer)
  140.                 rowIndexNum = value
  141.             End Set
  142.  
  143.         End Property
  144.  
  145.         Public Function EditingControlWantsInputKey(ByVal key As Keys, _
  146.             ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
  147.             Implements IDataGridViewEditingControl.EditingControlWantsInputKey
  148.  
  149.             ' Let the DateTimePicker handle the keys listed.
  150.             Select Case key And Keys.KeyCode
  151.                 Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
  152.                     Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp
  153.  
  154.                     Return True
  155.  
  156.                 Case Else
  157.                     Return Not dataGridViewWantsInputKey
  158.             End Select
  159.  
  160.         End Function
  161.  
  162.         Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
  163.             Implements IDataGridViewEditingControl.PrepareEditingControlForEdit
  164.  
  165.             ' No preparation needs to be done.
  166.  
  167.         End Sub
  168.  
  169.         Public ReadOnly Property RepositionEditingControlOnValueChange() _
  170.             As Boolean Implements _
  171.             IDataGridViewEditingControl.RepositionEditingControlOnValueChange
  172.  
  173.             Get
  174.                 Return False
  175.             End Get
  176.  
  177.         End Property
  178.  
  179.         Public Property EditingControlDataGridView() As DataGridView _
  180.             Implements IDataGridViewEditingControl.EditingControlDataGridView
  181.  
  182.             Get
  183.                 Return dataGridViewControl
  184.             End Get
  185.             Set(ByVal value As DataGridView)
  186.                 dataGridViewControl = value
  187.             End Set
  188.  
  189.         End Property
  190.  
  191.         Public Property EditingControlValueChanged() As Boolean _
  192.             Implements IDataGridViewEditingControl.EditingControlValueChanged
  193.  
  194.             Get
  195.                 Return valueIsChanged
  196.             End Get
  197.             Set(ByVal value As Boolean)
  198.                 valueIsChanged = value
  199.             End Set
  200.  
  201.         End Property
  202.  
  203.         Public ReadOnly Property EditingControlCursor() As Cursor _
  204.             Implements IDataGridViewEditingControl.EditingPanelCursor
  205.  
  206.             Get
  207.                 Return MyBase.Cursor
  208.             End Get
  209.  
  210.         End Property
  211.  
  212.         Protected Overrides Sub OnValueChanged(ByVal eventargs As EventArgs)
  213.  
  214.             ' Notify the DataGridView that the contents of the cell have changed.
  215.             valueIsChanged = True
  216.             Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
  217.             MyBase.OnValueChanged(eventargs)
  218.  
  219.         End Sub
  220.  
  221.     End Class
  222.  
  223.     '#################################################################################################################
  224.     Public dataGridView1 As New DataGridView()
  225.  
  226.  
  227.     Friend Sub dgv()
  228.         Me.dataGridView1.Dock = DockStyle.Fill
  229.         Me.Controls.Add(Me.dataGridView1)
  230.         Me.Text = "DataGridView calendar column demo"
  231.  
  232.  
  233.         Dim col As New CalendarColumn()
  234.         Me.dataGridView1.Columns.Add(col)
  235.         Me.dataGridView1.RowCount = 5
  236.         Dim row As DataGridViewRow
  237.         For Each row In Me.dataGridView1.Rows
  238.             row.Cells(0).Value = DateTime.Now
  239.         Next row
  240.     End Sub
  241.  
  242.  
  243.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  244.  
  245.         'avvia il datagridview.
  246.         Call dgv()
  247.     End Sub
  248. End Class
  249.  
  250. apri un nuovo progetto, e nel codice del Form1 ci incolli il codice di esempio sopra



If ok Then GOTO Avanza else GOTO Inizia

PM Quote