Missing members in custom progressbar - vb.net

I am new in this field and I find myself in difficulty, I have already looked for two days on the internet and I have not found anything or at least that is understandable within my reach.
I downloaded a file for a new ProgressBar in 3d, but I no longer have the option of [Step] and [PerformStep], how can I add these two properties?
Please help me, I've been running after it for days....
I downloaded a file from this post https://social.msdn.microsoft.com/Forums/vstudio/en-US/5d3eee65-730b-488f-a858-a341b8d61714/progressbar-with-percentage-label?forum=vbgeneral at the bottom of the page the link for RmCustProgressBar but I have problems.
Here The file for download is file txt https://onedrive.live.com/?authkey=%21ADU6srhRub2eM6M&cid=00D11ED12923BE81&id=D11ED12923BE81%21114&parId=root&o=OneUp
Public Sub righeNere()
Dim row_count As Integer = DataGridView1.Rows.Count
RmCustProgressBar1.MaxValue = row_count
RmCustProgressBar1.Step = 1
Dim currencyManager1 As CurrencyManager = CType(DataGridView1.BindingContext(DataGridView1.DataSource), CurrencyManager)
For Each rw As DataGridViewRow In DataGridView1.Rows
If rw.Cells(2).Style.BackColor = Color.Gold Or rw.Cells(3).Style.BackColor = Color.Gold Or rw.Cells(4).Style.BackColor = Color.Gold Or rw.Cells(5).Style.BackColor = Color.Gold Or rw.Cells(6).Style.BackColor = Color.Gold Or rw.Cells(7).Style.BackColor = Color.Gold Then
rw.Visible = True
Continue For
ElseIf rw.Cells(2).Style.BackColor = Color.White Or rw.Cells(3).Style.BackColor = Color.White Or rw.Cells(4).Style.BackColor = Color.White Or rw.Cells(5).Style.BackColor = Color.White Or rw.Cells(6).Style.BackColor = Color.White Or rw.Cells(7).Style.BackColor = Color.White Then
currencyManager1.SuspendBinding()
rw.Visible = False
currencyManager1.ResumeBinding()
RmCustProgressBar1.PerformStep()
End If
Next
End Subd

I assume that Step is a step size and that PerformStep simply adds this step to the Value property. Then you can add this functionality like this in the progress bar class:
Public Property [Step] As Integer
Public Sub PerformStep()
Value = Math.Min(MaxValue, Value + [Step])
'To refresh the progress bar immediately (optional)
Refresh()
End Sub
Setting the Value property invalidates the control, i.e. the new progress bar position will be displayed automatically, but maybe with some delay. If you want to refresh it immediately, you can force a redraw by calling Refresh(). See: Control.Refresh Method
Note that Step is a reserved word in VB, therefore we must put it in angle brackets. Instead, we could also call it StepSize.

Related

Dynamic entries from textfiles into FlowLayoutPanel

I'm currently working on a ToDo program, where you can simply add notes. (With the option to set priority and attachment) The Note will be saved as a textfile. Now I want to make an over view of the ToDo's which have to be done. In the end it's supposed to look like a list, one row for each Note, built like this:
TITLE.............................[Attachment Icon]..[Priority Icon]..[CheckBox]
The checkbox should always be on the very right side of the row.
My idea is to add a FlowLayoutPanel to a FlowLayoutPanel for every Note. In the child-FlowLayoutPanel I'll add the controls. My problem is that I have no Idea how to set the positions of the controls. I tried to add a label and use it as a space between the title and the other controls, but it doesn't really work.
Here's the code I currently have:
For Each File In Directory.GetFiles(myPath)
Dim tlp As New FlowLayoutPanel
tlp.BackColor = Color.Gray
tlp.Width = 260
tlp.FlowDirection = FlowDirection.TopDown
Dim lbl As New Label
lbl.AutoSize = True
lbl.Text = getInsert(File, 0)
lbl.Anchor = AnchorStyles.Right
lbl.ForeColor = Color.White
AddHandler lbl.Click, Sub() Me.getInsert(File, 0)
tlp.Height = 40
Dim cbx As New CheckBox
cbx.FlatStyle = FlatStyle.Flat
cbx.Text = ""
cbx.Width = 15
cbx.Height = 30
AddHandler cbx.CheckStateChanged, Sub() Me.deleteEntry(tlp)
Dim space As New Label
space.AutoSize = False
space.Text = ""
space.Height = 30
space.Anchor = AnchorStyles.Right
tlp.Controls.Add(lbl)
tlp.Controls.Add(Space)
tlp.Controls.Add(cbx)
Space.Width = tlp.Width - lbl.Width - cbx.Width - 15
mfp.Controls.Add(tlp)
Next
Here's an example:
todo_example
I hope anyone has a good idea how to solve this problem.
Thanks in advance :)

Datagridview image column moves on update

On my form i got datagridview which is populating by some data. There is also a combobx on this form and when selection change has happend then based on selected value - datagridview datasource is set to be nothing and then filled up again. Everything was working well until i decided to add additional datagridview image column which i placed on the end of grid and to show images based on text from some previous column text data. Unfortunetly i have problem with displaying images itself (red marks) and biggest problem is when i change combobox selection my additional datagrid image column is moving 1 position to left everytime combo is changed. I've spent whole day looking for issue but can't find any answer on that. I thought maybe that's because grid datasource is not being cleaned (nothing) but it is. Can you please help me out what could be a problem here? Below find my code and screenshoots of problem. Hope you help me to fix it as i am really stackoverflowed.
My Form Load event - that's where i load combobox:
Private Sub FrmTransportView_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RemoveHandler CboProjects.SelectedIndexChanged, AddressOf CboProjects_SelectedIndexChanged
Try
mydb.OpenConn()
If mydb.conn.State = ConnectionState.Open Then
Form.InitCombo(CboProjects, "SELECT * from tbProjekt", mydb.conn, "Nazwa", "Id")
mydb.CloseConn()
'ChangeControlsLanguage()
Trans = New Transport
Trans.ProjectId = CboProjects.SelectedValue
RefreshGridAfterProjectIdChanged()
AddHandler CboProjects.SelectedIndexChanged, AddressOf CboProjects_SelectedIndexChanged
End Try
End Sub
PopulateGrid method:
Public Sub PopulateGrid()
Try
If IsNothing(Trans.ListByProjectId_checkifanyrows()) Then
Me.BeginInvoke(New MethodInvoker(AddressOf Me.Close))
Else
Else
dgvTransport.DataSource = Nothing 'Clean datagrid before new data
dgvTransport.Refresh()
dgvTransport.DataSource = Trans.ListByProjectId()
AlignGrid()
PlaceImages()
End If
End Try
End Sub
Align method - placed within PopulateGrid method as you see when dgvTransport as set to nohing and then its detasource set to new data: Trans.ListByProjectId() now i am aligning it - hiding some columns etc... As you can see also i am adding this new image column... :
Private Sub AlignGrid()
Try
dgvTransport.Columns(0).Visible = False 'Project id
dgvTransport.Columns(1).Visible = False 'Id
dgvTransport.Columns(2).Visible = True 'Lp
dgvTransport.Columns(3).Visible = True 'Status
dgvTransport.Columns(4).Visible = True 'Dataprzyjazdu
dgvTransport.Columns(5).Visible = True 'DataRozpoczeciaZaladunku
dgvTransport.Columns(6).Visible = True 'DataOdjazdu
dgvTransport.Columns(7).Visible = True 'TypTransportu dgvTransport.Columns(8).Visible = False 'TypKontenera (reprezentacja liczbowa z tabeli tbTransport)
dgvTransport.Columns(9).Visible = True 'NumerKontenera
dgvTransport.Columns(10).Visible = True 'NumerCiezarowki
dgvTransport.Columns(11).Visible = True 'Plomba
dgvTransport.Columns(12).Visible = False 'Kierowca
dgvTransport.Columns(13).Visible = False 'Opis
dgvTransport.Columns(14).Visible = False 'Nazwa (nazwa projektu)
dgvTransport.Columns(15).Visible = True 'TypKontenera (reprezentacja za pomoca nazwy ze zlaczenia INNER JOIN))
Dim img As DataGridViewImageColumn = New DataGridViewImageColumn()
img.HeaderText = "Status2"
img.Name = "Status2"
dgvTransport.Columns.Insert(16, img)
'potrzebny aby zadzialalo: DgvMach.ColumnHeadersDefaultCellStyle.BackColor = Color.Gold
dgvTransport.EnableHeadersVisualStyles = False
'headers look
With dgvTransport.ColumnHeadersDefaultCellStyle
'The way to do this is to set the EnableHeadersVisualStyles flag for the data grid view to False, and set the background colour via the ColumnHeadersDefaultCellStyle.BackColor property. For example, to set the background colour to blue, use the following (or set in the designer if you prefer):
'If you do not set the EnableHeadersVisualStyles flag to False, then the changes you make to the style of the header will not take effect, as the grid will use the style from the current users default theme. The MSDN documentation for this property is here.
.BackColor = Color.White
.ForeColor = Color.Black
.Font = New Font("Ariel", 10, FontStyle.Regular)
.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
dgvTransport.AllowUserToAddRows = False
dgvTransport.[ReadOnly] = True
dgvTransport.MultiSelect = False
dgvTransport.SelectionMode = DataGridViewSelectionMode.FullRowSelect 'zaznacza caly wiersz po kliknieciu
dgvTransport.AutoSizeColumnsMode = DataGridViewAutoSizeColumnMode.Fill 'WAZNE!!!: RESIZUJE CALY CONTENT GRIDA NIE ZOSSTAWIAJAC CIEMNEGO TLA !!!
dgvTransport.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
With dgvTransport.DefaultCellStyle
.BackColor = Color.White
.ForeColor = Color.Black
.Font = New Font("Ariel", 9, FontStyle.Regular)
.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
'This will disable row autosizing and manual row resizing. To set the row height you can use the Height and MinimumHeight properties of the RowTemplate.
dgvTransport.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
dgvTransport.AllowUserToResizeRows = False
End Sub
FrmTransportView_Shown event:
Private Sub FrmTransportView_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
AddHandler dgvTransport.SelectionChanged, AddressOf dgvTransport_SelectionChanged
End Sub
RefreshGridAfterProjectIdChanged
Public Sub RefreshGridAfterProjectIdChanged()
Trans.ProjectId = CboProjects.SelectedValue
PopulateGrid()
End Sub
CboProjects_SelectedIndexChanged
Private Sub CboProjects_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CboProjects.SelectedIndexChanged
RefreshGridAfterProjectIdChanged()
End Sub
PlaceImages
Private Sub PlaceImages()
For i As Integer = 0 To dgvTransport.Rows.Count - 1
Dim sHeader As String = dgvTransport.Columns(16).Name
If sHeader = "Status2" Then
Dim LINK = dgvTransport.Rows(i).Cells(8).Value
If LINK.ToString.Contains("1") Then
Dim Img As New DataGridViewImageCell
Img.Value = My.Resources._1
dgvTransport.Rows(i).Cells(16).Value = Img.Value
End If
If LINK.ToString.Contains("2") Then
Dim Img As New DataGridViewImageCell
Img.Value = My.Resources._2
dgvTransport.Rows(i).Cells(16).Value = Img.Value
End If
If LINK.ToString.Contains("3") Then
Dim Img As New DataGridViewImageCell
Img.Value = My.Resources._3
dgvTransport.Rows(i).Cells(16).Value = Img.Value
End If
End If
Next
End Sub
That's how it looks for first form load: (strange thing is column index of image column (Status2) is 0 - should be 16 as i placed index for that column to 16 in Align method.. As you see also not images are showing up...
Now when i am going to change selection in combobox:
of course as you can note from code this method handler is called: CboProjects_SelectedIndexChanged
so then again grid datasource will be set to Nothing, populate again, then align gird..
and that's what is shown after: (see indexes - also some image show up and column "Status2" was moved to left..)
3rd combobox change etc...
Hope to find someone here to help me out as i really have no idea how to fix that. Hope everything is clear.
Sorry this is coming a little late. Just a suggestion - I didn't experiment with it. Try to insert the DataGridImageColumn first before editing the visibility of the other columns.
Not too related, but in your AlignGrid sub, the static properties like ".BackColor" can be set on design just to reduce code.
Let us know your observations.
Thanks

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

Have multiple objects in a With statement in VB?

I have a lot of labels in VB that I use in With statement to set their properties.
Problem
Is there any way I can do something like the following:
With lblA, lblB, lblC
.fontColor = color.Red
End With
Is this possible, or do I have to manually do a With statement for each of them?
There is a shorter and more readable version of your solution:
For Each lbl As Label In {lblA, lblB, lblC}
With lbl
'...
End With
Next
I would keep those types of items in a list and then apply a for each loop on them, assuming they are all of the same type (or at least base type). Assuming you are using controls of type label this would be a solution. Note that I've modified .fontColor to .ForeColor so that this example works with the Label class:
Dim lblList as new List(of Label) ({lblA, lblB, lblC})
lblList.ForEach(sub(x) x.Fore Color = color.red)
Since you've posted your solution, you could still do the following to avoid the iteration loop over the array you made (which is why I do this as a list) not having to take into account the array size or anything:
lblList.ForEach(Sub(x)
With x
.BackColor = Color.Black
.Dock = DockStyle.Top
.TextAlign = ContentAlignment.MiddleCenter
End With
End Sub)
Here is the way I ended up doing it:
Dim arrayMe As Label() = {lblA, lblB, lblC}
For count = 0 To arrayMe.Length - 1 Step 1
With arrayMe(count)
.BackColor = Color.Black
.Dock = DockStyle.Top
.TextAlign = ContentAlignment.MiddleCenter
End With
Next
There are other ways to do it, but I found this to be useful.

Trouble with Timer_tick not stopping

I'm very new to programming and vb.net, trying to self teach more so as a hobby, as I have an idea for a program that I would find useful, but I am having trouble getting past this issue and I believe it is to do with the timer.
I have a form of size.(600,600) with one button of size.(450,150) that is set location(100,50) on the form. When clicked I want to move down it's own height, then add a new button in it's place. The code included below works as desired for the first two clicks, but on the third click the button keeps moving and the autoscroll bar extends. I initially thought it was the autoscroll function or the location property, but realised that as the button keeps moving, the timer hasn't stopped. I am aware that the code is probably very clunky in terms of achieving the outcome, and that there are a few lines/variables that are currently skipped over by the compiler (these are from older attempts to figure this out).
I have looked around and can't find the cause of my problem. Any help would be greatly appreciated. Apologies if the code block looks messy - first go.
Public Class frmOpenScreen
Dim intWButtons, intCreateButtonY, intCreateButtonX 'intTimerTick As Integer
Dim arrWNames() As String
Dim ctrlWButtons As Control
Dim blnAddingW As Boolean
Private Sub btnCreateW_Click(sender As System.Object, e As System.EventArgs) Handles btnCreateW.Click
'Creates new Button details including handler
Dim strWName, strWShort As String
Dim intCreateButtonY2 As Integer
Static intNumW As Integer
Dim B As New Button
strWName = InputBox("Please enter the name name of the button you are creating. Please ensure the spelling is correct.", "Create W")
If strWName = "" Then
MsgBox("Nothing Entered.")
Exit Sub
End If
strWShort = strWName.Replace(" ", "")
B.Text = strWName
B.Width = 400
B.Height = 150
B.Font = New System.Drawing.Font("Arial Narrow", 21.75)
B.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
B.Anchor = AnchorStyles.Top
B.Margin = New Windows.Forms.Padding(0, 0, 0, 0)
'Updates Crucial Data (w name array, number of w buttons inc Create New)
If intNumW = 0 Then
ReDim arrWNames(0)
Else
intNumW = UBound(arrWNames) + 1
ReDim Preserve arrWNames(intNumW)
End If
arrWNames(intNumW) = strWShort
intNumW = intNumW + 1
intWButtons = WButtonCount(intWButtons) + 1
'updates form with new button and rearranges existing buttons
intCreateButtonY = btnCreateW.Location.Y
intCreateButtonX = btnCreateW.Location.X
‘intTimerTick = 0
tmrButtonMove.Enabled = True
‘Do While intTimerTick < 16
‘ 'blank to do nothing
‘Loop
'btnCreateW.Location = New Point(intCreateButtonX, intCreateButtonY + 150)
B.Location = New Point(intCreateButtonX, intCreateButtonY)
Me.Controls.Add(B)
B.Name = "btn" & strWShort
intCreateButtonY2 = btnCreateW.Location.Y
If intCreateButtonY2 > Me.Location.Y Then
Me.AutoScroll = False
Me.AutoScroll = True
Else
Me.AutoScroll = False
End If
'MsgBox(intCreateButtonY)
End Sub
Function WButtonCount(ByRef buttoncount As Integer) As Integer
buttoncount = intWButtons
If buttoncount = 0 Then
Return 1
End If
Return buttoncount
End Function
Public Sub tmrButtonMove_Tick(sender As System.Object, e As System.EventArgs) Handles tmrButtonMove.Tick
Dim intTimerTick As Integer
If intTimerTick > 14 Then
intTimerTick = 0
End If
If btnCreateW.Location.Y <= intCreateButtonY + 150 Then
btnCreateW.Top = btnCreateW.Top + 10
End If
intTimerTick += 1
If intTimerTick = 15 Then
tmrButtonMove.Enabled = False
End If
End Sub
End Class
So my current understanding is that the tick event handler should be increasing the timertick variable every time it fires, and that once it has hits 15 it should diable the timer and stop the button moving, but it is not doing so.
Thanks in advance.
IntTimerTick is initialized to 0 at the beginning of every Tick event. This won't happen if you declare it to be static:
Static Dim intTimerTick As Integer