Datepicker datasave event - vb.net

I am trying to use windows forms vb.net. Created a simple form with datepicker controls.
These controls are dynamically created. I am using infragistics datepicker here
dtpicker = New UltraDateTimeEditor
dtpicker.Name = "Date" + i.ToString()
dtpicker.MaskInput = "{date} hh:mm"
dtpicker.MaskDisplayMode = MaskMode.IncludeBoth
dtpicker.SpinButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always
dtpicker.Height = 20
dtpicker.Width = 140
'horizontal
dtpicker.Location = New Point((i * 140), 100)
AddHandler dtpicker.Leave, AddressOf dtpicker_Leave
I have added leave event. But the problem is leave event is fired twice. Please suggest me how to fix or use other correct event.
My data saving logic on leave event looks like this
If Not DBNull.Value.Equals(chkdtFlowPanel.Rows.Item(0).Item("ConveyanceID")) AndAlso Not DBNull.Value.Equals(chkdtFlowPanel.Rows.Item(0).Item("TripID")) Then
ScreenProperty.ARG_ConveyanceID = chkdtFlowPanel.Rows.Item(0).Item("ConveyanceID")
ScreenProperty.ARG_TripID = chkdtFlowPanel.Rows.Item(0).Item("TripID")
Dim prevDatevalue As Object = Nothing
For Each o As Object In UltraPanel1.ClientArea.Controls
If TypeOf (o) Is UltraDateTimeEditor Then
Dim datePicker As UltraDateTimeEditor = o
If prevDatevalue <> Nothing AndAlso datePicker.Value <> Nothing Then
If datePicker.Value < prevDatevalue Then
' Do something Previous value is Lesser
'lblSuccess.Text = "Please verify date entered."
'lblSuccess.ForeColor = Color.Red
Exit Sub
End If
End If
ScreenProperty.ARG_CheckPointTimeID = Convert.ToInt32(datePicker.Tag.Split(","c)(0))
ScreenProperty.ARG_TerminalCheckPointID = Convert.ToInt32(datePicker.Tag.Split(","c)(1))
ScreenProperty.ARG_CheckPointTimeValue = datePicker.Value
Helper.InsertCheckPointTimes(CType(ScreenProperty, KMCommonUITemplates.CUTScreenProperty), Me)
prevDatevalue = datePicker.Value
'lblSuccess.Text = "Data Saved Successfully."
'lblSuccess.ForeColor = Color.Green
End If
Next
'Else
' lblSuccess.Text = "Selected Order does not have Trip/Conveyance created."
' lblSuccess.ForeColor = Color.Red
End If
'Helper.GetCheckPointFlowByTerminalID(CType(ScreenProperty, KMCommonUITemplates.CUTScreenProperty), Me)
ClearText()

Related

Background worker Picturebox gif

I have a picturebox with a gif (the gif works). My program is written to open up a document file that is located on a drive on the other side of the country, so it takes some time.
I have set picturebox.visible = true when the program starts the connection process, but the gif does not animate during this process; but only when idling.
A Google search led me to the background worker control, but in all the examples I found, I could not find one that could either:
Just have the gif running in a background worker permanently (I assume this wouldn't use up too much memory, as it is just a gif)
or
Have the gif animate while the application is connecting
Can anyone help?
From the comments, I'm assuming that this entire thing needs to be in a backgroundworker.dowork, but I just keep getting errors because I'm changing controls here.
Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
'Displaying "Loading"
picLoading.Visible = True
tblMain.Visible = False
'If the application has loaded at least one sheet
If FirstLoad = 2 Then
worksheet.Cells(1, 31).Value = ""
workbook.Save()
workbook.Close(False)
End If
Filter = cmbFilter.Text
'Go to page 1
CurrentPage = 0
workbook = APP.Workbooks.Open(Path & "\" & Filter & ".xlsx")
worksheet = workbook.Worksheets("Sheet1")
If Convert.ToString(worksheet.Cells(1, 31).Value) <> "" Then
MsgBox("The sheet for " & Filter & " is currently being used by " & Convert.ToString(worksheet.Cells(1, 31).Value) & ".")
workbook.Close(False)
Else
FirstLoad = 2 'Indicate that the application has loaded at least one sheet
worksheet.Cells(1, 31).Value = User
'Make all textboxes and comboboxes visible = false
txtSearch.Visible = False : btnSort.Visible = False : btnSortUrgency.Visible = False : btnSave.Visible = False : btnPrevious.Visible = False : btnNext.Visible = False
Label1.Visible = False
Label2.Visible = False
'Count entries and calculate how many pages there are
Entries = worksheet.Range("B1048576").End(Excel.XlDirection.xlUp).Row 'Count how many entries there are (the first row always counts as an entry)
TotalPages = Math.Ceiling(Entries / 8) - 1 'Calculate how many pages there are
If TotalPages = (Entries / 8) - 1 Then
TotalPages = TotalPages + 1
End If
'Determine how many entries are on the last page
LastEntries = Entries
While LastEntries > 8 'Keep subtracting by 8 to determine how many entries are going to be on the last page
LastEntries = LastEntries - 8
End While
'Add categories for the Urgency comboboxes
Me.cmbUrgency1.DrawMode = DrawMode.OwnerDrawFixed
Me. cmbUrgency1.DropDownStyle = ComboBoxStyle.DropDownList
Me. cmbUrgency1.ItemHeight = 15
Me. cmbUrgency1.BeginUpdate()
cmbUrgency1.Items.Clear()
Me. cmbUrgency1.Items.Add("1")
Me. cmbUrgency1.Items.Add("2")
Me. cmbUrgency1.Items.Add("3")
Me. cmbUrgency1.Items.Add("4")
cmbUrgency1.EndUpdate()
Me. cmbUrgency2.DrawMode = DrawMode.OwnerDrawFixed
Me. cmbUrgency2.DropDownStyle = ComboBoxStyle.DropDownList
Me. cmbUrgency2.ItemHeight = 15
Me. cmbUrgency2.BeginUpdate()
cmbUrgency2.Items.Clear()
Me. cmbUrgency2.Items.Add("1")
Me. cmbUrgency2.Items.Add("2")
Me. cmbUrgency2.Items.Add("3")
Me. cmbUrgency2.Items.Add("4")
cmbUrgency2.EndUpdate()
Me. cmbUrgency3.DrawMode = DrawMode.OwnerDrawFixed
Me. cmbUrgency3.DropDownStyle = ComboBoxStyle.DropDownList
Me. cmbUrgency3.ItemHeight = 15
Me. cmbUrgency3.BeginUpdate()
cmbUrgency3.Items.Clear()
Me. cmbUrgency3.Items.Add("1")
Me. cmbUrgency3.Items.Add("2")
Me. cmbUrgency3.Items.Add("3")
Me. cmbUrgency3.Items.Add("4")
Urgency3.EndUpdate()
Me.Urgency4.DrawMode = DrawMode.OwnerDrawFixed
Me.Urgency4.DropDownStyle = ComboBoxStyle.DropDownList
Me.Urgency4.ItemHeight = 15
Me.Urgency4.BeginUpdate()
Urgency4.Items.Clear()
Me.Urgency4.Items.Add("1")
Me.Urgency4.Items.Add("2")
Me.Urgency4.Items.Add("3")
Me.Urgency4.Items.Add("4")
Urgency4.EndUpdate()
Dim DataCollection As New AutoCompleteStringCollection()
txtBlank.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank.AutoCompleteCustomSource = DataCollection
txtBlank2.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank2.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank2.AutoCompleteCustomSource = DataCollection
txtBlank3.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank3.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank3.AutoCompleteCustomSource = DataCollection
txtBlank3.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank3.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank3.AutoCompleteCustomSource = DataCollection
workbook.Save()
Call DisplayInfo()
End If
End Sub

Clearing Panel Jumps to Value Change Event of DatePicker and Never ends the loop

Here I am using Panel with some dynamic datetime editors on windows forms with VB.net. Before loading the panel i am trying to clear the panel. But this cause value changed event to run continuously and will never stop
When the date is entered in dynamically created datetime editor, value changed event is continuously running and will never stop.
How can I fix this
My code is as Below
Private Function LoadFlow()
Me.UltraPanel1.ClientArea.Controls.Clear()
Dim i As Integer = 0
'Check if datatable has rows and is not null
If dtFlowPanel.Rows.Count > 0 AndAlso dtFlowPanel IsNot Nothing Then
Do While (i < dtFlowPanel.Rows.Count)
'DatePicker
dtpicker = New UltraDateTimeEditor
dtpicker.Name = "Date" + i.ToString()
dtpicker.MaskInput = "{date} hh:mm"
dtpicker.MaskDisplayMode = MaskMode.IncludeBoth
dtpicker.SpinButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always
dtpicker.Height = 20
dtpicker.Width = 140
'horizontal
dtpicker.Location = New Point((i * 140), 100)
AddHandler dtpicker.ValueChanged, AddressOf dtpicker_ValueChanged
If Not IsDBNull(dtFlowPanel.Rows(i)("CheckPointTimeValue")) Then
dtpicker.Value = dtFlowPanel.Rows(i)("CheckPointTimeValue")
Else
dtpicker.Value = Nothing
End If
Me.UltraPanel1.ClientArea.Controls.Add(dtpicker)
i = (i + 1)
Loop
End If
Return Nothing
End Function
My value changed event
Private Sub dtpicker_ValueChanged(sender As Object, e As EventArgs)
If Not DBNull.Value.Equals(chkdtFlowPanel.Rows.Item(0).Item("ConveyanceID")) AndAlso Not DBNull.Value.Equals(chkdtFlowPanel.Rows.Item(0).Item("TripID")) Then
ScreenProperty.ARG_ConveyanceID = chkdtFlowPanel.Rows.Item(0).Item("ConveyanceID")
ScreenProperty.ARG_TripID = chkdtFlowPanel.Rows.Item(0).Item("TripID")
Dim prevDatevalue As Object = Nothing
For Each o As Object In UltraPanel1.ClientArea.Controls
If TypeOf (o) Is UltraDateTimeEditor Then
Dim datePicker As UltraDateTimeEditor = o
If datePicker.Value <> Nothing Then
If prevDatevalue <> Nothing Then
If datePicker.Value < prevDatevalue Then
' Do something Previous value is Lesser
'lblSuccess.Text = "Please verify date entered."
'lblSuccess.ForeColor = Color.Red
Exit Sub
End If
End If
ScreenProperty.ARG_CheckPointTimeID = Convert.ToInt32(datePicker.Tag.Split(","c)(0))
ScreenProperty.ARG_TerminalCheckPointID = Convert.ToInt32(datePicker.Tag.Split(","c)(1))
ScreenProperty.ARG_CheckPointTimeValue = datePicker.Value
Helper.InsertCheckPointTimes(CType(ScreenProperty, KMCommonUITemplates.CUTScreenProperty), Me)
prevDatevalue = datePicker.Value
'ClearText()
End If
'lblSuccess.Text = "Data Saved Successfully."
'lblSuccess.ForeColor = Color.Green
End If
Next
'Else
' lblSuccess.Text = "Selected Order does not have Trip/Conveyance created."
' lblSuccess.ForeColor = Color.Red
Helper.GetCheckPointFlowByTerminalID(CType(ScreenProperty, KMCommonUITemplates.CUTScreenProperty), Me)
LoadFlow()
End If
End Sub
Since the event handler code is calling LoadFlow that in turn appears to trigger the eventhandler, you are entering an infinite loop.
Before the statement Me.UltraPanel1.ClientArea.Controls.Clear() in LoadFlow remove any eventhandlers. Something like this:
For Each c As Control In UltraPanel1.ClientArea.Controls
Dim dtp As UltraDateTimeEditor
dtp = TryCast(c, UltraDateTimeEditor)
If dtp IsNot Nothing Then
RemoveHandler dtp.ValueChanged, AddressOf DateTimePicker_ValueChanged
End If
Next

Visual Basic Datagrid View change row colour

Every other change to the datagrid view works fine but for some reason the row color just wont change.
Ive debugged and my application goes through the loop to change the row color.
Also I have a button that gives the datagrid view a new list and colors the rows accordingly, when I click the button the row colors changes do work!
Public Sub New(measuredValues As List(Of MeasuredValuesModel), valueType As ValueType)
IsFiltered = False
' This call is required by the designer.
InitializeComponent()
MeasuredValuesList = measuredValues
uxGrid.DataSource = MeasuredValuesList
uxGrid.Columns("StepID").Visible = False
uxGrid.Font = New Font("Arial", 10, FontStyle.Bold)
For Each c As DataGridViewColumn In uxGrid.Columns
Dim Column As DataGridViewColumn = c
c.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
Next
If valueType = StepItem.ValueType.CalculatedValues Then
uxButtonFilter.Visible = False
uxGrid.Columns("DISPOSITION").Visible = False
End If
For Each gridRow As DataGridViewRow In uxGrid.Rows
If gridRow.Cells("PASSFAIL").Value.ToString() = "FAIL" And (gridRow.Cells("DISPOSITION").Value.ToString() = "Y" Or gridRow.Cells("DISPOSITION").Value.ToString() = "N/A") Then
gridRow.DefaultCellStyle.BackColor = Color.Red
ElseIf gridRow.Cells("PASSFAIL").Value.ToString() = "FAIL" And (gridRow.Cells("DISPOSITION").Value.ToString() = "N" Or gridRow.Cells("DISPOSITION").Value.ToString() = "N/A") Then
gridRow.DefaultCellStyle.BackColor = Color.Orange
End If
Next
uxStepID.Text = MeasuredValuesList.FirstOrDefault.StepID
' Add any initialization after the InitializeComponent() call.
'TODO binding
End Sub
Here is the button that works for changing row color.
Maybe it works because it's pressed after the grid has been created? Im not too sure.
Private Sub uxButtonFilter_Click(sender As Object, e As EventArgs) Handles uxButtonFilter.Click
If IsFiltered = True Then
uxGrid.DataSource = MeasuredValuesList
For Each gridRow As DataGridViewRow In uxGrid.Rows
If gridRow.Cells("PASSFAIL").Value.ToString() = "FAIL" And (gridRow.Cells("DISPOSITION").Value.ToString() = "Y" Or gridRow.Cells("DISPOSITION").Value.ToString() = "N/A") Then
gridRow.DefaultCellStyle.BackColor = Color.Red
ElseIf gridRow.Cells("PASSFAIL").Value.ToString() = "FAIL" And (gridRow.Cells("DISPOSITION").Value.ToString() = "N" Or gridRow.Cells("DISPOSITION").Value.ToString() = "N/A") Then
gridRow.DefaultCellStyle.BackColor = Color.Orange
End If
Next
Its the exact same loop but it seems to work fine when i use the button.
Is it possible that your datagridview isn't loaded fully when you try to recolor the rows?
Since you are setting the datasource, you should put your code that affects the grid after you can make sure that it is finished loading. The column widths change because it is not dependent on the data in the grid, but your colouring is.
Catch the uxGrid.databindingComplete event and try colouring the rows in there

Windows form controls become grey overlay

I have created a winform application in vb.net, it contains a parent container and other child forms. When one of the child form which contains a data gridview with some cell formatting, loading the other controls became gray colour overlayed.
Note: the gridview is created using the data from database and the color is applied according to the value in the cells. The color changing using the cellformating method. I have tried double buffering.. but it didn't help. In red color circle it is label and in green color, it is button.
Find the code below for cell formatting:
Private Sub dataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dataGridView1.CellFormatting
Try
Dim i As Integer
For i = 0 To dataGridView1.RowCount
If (i = (dataGridView1.RowCount)) Then
Exit For
Else
Dim dt As DateTime = DateTime.Parse(dataGridView1.Rows(i).Cells(6).Value.ToString())
dt = dt.AddHours(12)
Dim ts As TimeSpan = dt.Subtract(DateTime.Now)
Dim s As String = dataGridView1.Rows(i).Cells(7).Value.ToString()
If s = "Ready to Collect" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.LimeGreen
dataGridView1.Rows(i).Cells(8).Value = "-----"
ElseIf s = "Completed" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.GreenYellow
dataGridView1.Rows(i).Cells(8).Value = "-----"
ElseIf s = "Out of Stock" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.Red
dataGridView1.Rows(i).Cells(8).Value = "-----"
ElseIf s = "Sent" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.OrangeRed
If ts.CompareTo(TimeSpan.Zero) < 0 Then
dataGridView1.Rows(i).Cells(8).Value = "Process Immediately"
dataGridView1.Rows(i).Cells(8).Style.BackColor = Color.OrangeRed
Else
dataGridView1.Rows(i).Cells(8).Value = String.Format("{0:D2}:{1:D2}", ts.Hours, ts.Minutes)
End If
ElseIf s = "Cancelled" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.White
dataGridView1.Rows(i).Cells(8).Value = "-----"
End If
End If
Next
Catch ex As Exception
System.Diagnostics.Trace.TraceError(ex.Message)
End Try
Check DoEvents. Maybe this helps you.

set the location of all open forms

this code lets me set the location of the form each time I drag my map.
Private Sub map_OnMapDrag() Handles map.OnMapDrag
If f2c1.Visible Then
f2c1.Location = camera1.LocalPosition + New Point(20, -240)
End If
If f2c2.Visible Then
f2c2.Location = camera2.LocalPosition + New Point(20, -240)
End If
If f2c3.Visible Then
f2c3.Location = camera3.LocalPosition + New Point(20, -240)
End If
End Sub
however, I want it on a public sub..
and this code, which I think gets all the visible forms ..
Dim forms = Application.OpenForms.OfType(Of frmCamera)()
While forms.Count > 0
forms(forms.Count - 1).Visible = True
End While
how can I make it so that all visible forms gets their location everytime I drag it, so that even if I dynamically added another form it won't be a problem. that's my goal.
can you guys fix this for me..
Dim forms = Application.OpenForms.OfType(Of frmCamera)()
While forms.Count > 0
forms(forms.Count - 1).Visible = True
End While
forms.Location = 'location that I want
Try this:
Dim forms As Collections.Generic.IEnumerable(Of frmMain) = Application.OpenForms.OfType(Of frmMain).Where(Function(frm) frm.Visible)
For Each f As Form In forms
f.Location = New Point(0, 0) ' set coordinate as needed
Next