textbox lines into listview subitems vb.net - vb.net

i have an app that detect wifi networks
i have a listviewitems with wifi ssid , signal and security and i have
a richtextbox that each line contains mac address of each ssid that is ordred
i want to add each line to each item as subitem
i used this code but number of items are changeable
LVW.Items(0).SubItems(3).Text = RichTextBox1.Lines(0)
LVW.Items(1).SubItems(3).Text = RichTextBox1.Lines(1)
LVW.Items(2).SubItems(3).Text = RichTextBox1.Lines(2)
LVW.Items(4).SubItems(3).Text = RichTextBox1.Lines(4)
LVW.Items(5).SubItems(3).Text = RichTextBox1.Lines(5)
LVW.Items(6).SubItems(3).Text = RichTextBox1.Lines(6)
LVW.Items(7).SubItems(3).Text = RichTextBox1.Lines(7)
LVW.Items(8).SubItems(3).Text = RichTextBox1.Lines(8)
LVW.Items(9).SubItems(3).Text = RichTextBox1.Lines(9)
LVW.Items(10).SubItems(3).Text = RichTextBox1.Lines(10)
LVW.Items(11).SubItems(3).Text = RichTextBox1.Lines(11)
LVW.Items(12).SubItems(3).Text = RichTextBox1.Lines(12)
LVW.Items(13).SubItems(3).Text = RichTextBox1.Lines(13)
LVW.Items(14).SubItems(3).Text = RichTextBox1.Lines(14)
LVW.Items(15).SubItems(3).Text = RichTextBox1.Lines(15)
here's the picture

Try this:
If RichTextBox1.Lines.Count > 0 And LVW.Items.Count = RichTextBox1.Lines.Count Then
For i As Integer = 0 To RichTextBox1.Lines.Count - 1
LVW.Items(i).SubItems(3).Text = RichTextBox1.Lines(i)
Next
Else
MsgBox("Invalid number of lines in RichTextBox1")
End If

Related

Remove Large Spacing on a Graph Visual Basic

I am working on a program and one feature is to show a graph of accrued points by game. I have successfully created the graph but cannot work out how to get rid of the big gaps at either side. I have tried reducing padding and margins to 0 but to no avail. Any help would be greatly appreciated. :)
Image of graph:
Chart1.Series.Clear()
Chart1.Titles.Clear()
Chart1.ChartAreas.Clear()
Chart1.Show()
Chart1.AlignDataPointsByAxisLabel()
Chart1.Titles.Add(names(search))
Chart1.ChartAreas.Add("Default")
With Chart1.ChartAreas("Default")
.AxisX.Interval() = 5
.AxisY.Interval() = 1
.AxisY.Title = "Number of Wins"
.AxisX.Title = "Game"
.AxisX.CustomLabels.Add(0, 60, "low")
End With
Chart1.SetBounds(270, 200, 510, 250)
Dim ref As Integer = 0
For Each item As DictionaryEntry In gamespoints
If item.Value > 0 Then
ref = ref + 1
Chart1.Series.Add(item.Key)
If item.Value = max And ref Mod 2 = 0 Then
Chart1.Series(item.Key).Color = Color.Green
ElseIf item.Value = max Then
Chart1.Series(item.Key).Color = Color.LimeGreen
ElseIf ref Mod 2 = 0 Then
Chart1.Series(item.Key).Color = Color.Black
Else
Chart1.Series(item.Key).Color = Color.DarkGray
End If
Chart1.Series(item.Key).Points.AddXY(0, item.Value)
End If
Next

Dev Express chart Not Updating Second Time in Vb.net

For the first time when I run my window application it will successfully run, but when I change the database column and binding then it gives me an error that specific data column is not there in database; also I am make null chart datasource but it gives an error. Please help.
Dim ctrArr As Integer
Dim serCnt As Integer
Dim series1 As New Series
Dim seriesFound As Boolean = False
For serCnt = 0 To ctrChart.Series.Count - 1
ctrChart.Series(0).ArgumentDataMember = ""
ctrChart.Series(0).ValueDataMembers(0) = ""
ctrChart.Series(0).Visible = False
Next
For ctrArr = 0 To gStrYAxisParamArray.Length - 1 'deptname'
For serCnt = 0 To ctrChart.Series.Count - 1
If UCase(Trim(gStrYAxisParamArray(ctrArr))) = UCase(ctrChart.Series(serCnt).Name.ToString) Then
ctrChart.Series(serCnt).ArgumentDataMember = ""
ctrChart.Series(serCnt).ValueDataMembers(0) = ""
ctrChart.Series(serCnt).Visible = True
ctrChart.Series(serCnt).ArgumentDataMember = gxAxis
ctrChart.Series(serCnt).ValueDataMembers.Item(0) = Trim(gStrYAxisParamArray(ctrArr))
seriesFound = True
Exit For
End If
Next
If seriesFound = False Then
series1 = New Series(Trim(gStrYAxisParamArray(ctrArr)).ToString, ViewType.Bar)
'ctrChart.Series.AddRange(New Series() {series1, series2})
ctrChart.Series.Add(series1)
series1.ArgumentDataMember = ""
series1.ValueDataMembers(0) = ""
series1.Visible = True
series1.ArgumentDataMember = gxAxis
series1.Label.Border.Visible = False
series1.ValueDataMembers(0) = Trim(gStrYAxisParamArray(ctrArr))
series1.LegendText = Trim(gStrYAxisParamArray(ctrArr).ToString)
End If
seriesFound = False
Next
cmbSeries.Items.Clear()
For ctrArr = 0 To ChrtStockDept.Series.Count - 1
With cmbSeries.Items
cmbSeries.Items.Add(ChrtStockDept.Series(ctrArr).Name.ToString)
End With
Next

VB IF statement to ask if NULL then apply default image instead

Inherited a VB website and am new to vb programming, so steep learning curve.
I have a site that searches and list all currently available cars in the UK for a leasing company.
the vehicle data is provided by an external comapany and links all the tech specs etc and images to a keyID. However...
If the vehicle has not been assigned an image it is not counted or displayed. I want to add an IF statement so that if the ImageId is Null then it will display a default 'awaiting image' jpg and would therefore still be listed to the public.
the page is http://www.carmyke.co.uk/search_prices.aspx with the 'Vans' dropping the most from the list.
I have included the code I think I need to update.
I think I need an IF statement for the .ImageId that if the SQL returns NULL then it uses a default image located in the same folder as defined by the appsettings
Hope this makes sense!?
<--- THE CODE --->
#Region "Methods"
Private Function GetVehicle(ByVal SearchBy As SearchBy, _
ByVal SearchText As String) As Data.LeasingPrices.Vehicle
Dim _Vehicle As New Data.LeasingPrices.Vehicle
Try
Dim _SQL As New Net.SQL
_SQL.AppendSQL("SELECT TOP 1 * ")
_SQL.AppendSQL("FROM vw_carmyke_Rates_Business ")
_SQL.AppendSQL("LEFT OUTER JOIN carmyke_SpecialOffers ON vw_carmyke_Rates_Business.CVehicleId = carmyke_SpecialOffers.CVehicleId ")
Select Case SearchBy
Case Hydrate.SearchBy.Make
_SQL.AppendSQL("WHERE Make = #SearchText ")
Case Hydrate.SearchBy.Model
_SQL.AppendSQL("WHERE MakeModel = #SearchText ")
Case Hydrate.SearchBy.Derivative
_SQL.AppendSQL("WHERE MakeModelDerivative = #SearchText ")
End Select
_SQL.AppendSQL("ORDER BY Rental_48_40;")
_SQL.AddParameter("#SearchText", SearchText, SqlDbType.VarChar)
_SQL.ConnectReader()
If _SQL.Validation.NoErrors Then
If _SQL.Reader.Read() Then
With _Vehicle
.CVehicleId = _SQL.Reader.SQLString("CVehicleId").ToInteger()
.Van = _SQL.Reader.SQLString("BodyStyle").Contains("Van")
.Make = _SQL.Reader.SQLString("Make")
.Model = _SQL.Reader.SQLString("Model")
.Derivative = _SQL.Reader.SQLString("Derivative")
.ImageId = _SQL.Reader.SQLString("ImageId") & ".jpg"
.Co2 = _SQL.Reader.SQLString("Co2").ToInteger()
.P11d = _SQL.Reader.SQLString("P11d").ToDouble()
.Business = _SQL.Reader.SQLString("Business").ToBoolean()
.Personal = _SQL.Reader.SQLString("Personal").ToBoolean()
.Details = _SQL.Reader.SQLString("Details")
.OfferPrice = _SQL.Reader.SQLString("OfferPrice").ToDouble()
If .OfferPrice = 0 Then _
.OfferPrice = _SQL.Reader.SQLString("Offer_48_40").ToDouble()
If .OfferPrice = 0 Then _
.OfferPrice = _SQL.Reader.SQLString("Rental_48_40").ToDouble()
.Commercial = _SQL.Reader.SQLString("Commercial").ToBoolean()
.Offer_24_20 = _SQL.Reader.SQLString("Offer_24_20").ToDouble()
.Offer_24_40 = _SQL.Reader.SQLString("Offer_24_40").ToDouble()
.Offer_24_60 = _SQL.Reader.SQLString("Offer_24_60").ToDouble()
.Offer_36_30 = _SQL.Reader.SQLString("Offer_36_30").ToDouble()
.Offer_36_60 = _SQL.Reader.SQLString("Offer_36_60").ToDouble()
.Offer_36_90 = _SQL.Reader.SQLString("Offer_36_90").ToDouble()
.Offer_48_40 = _SQL.Reader.SQLString("Offer_48_40").ToDouble()
.Offer_48_80 = _SQL.Reader.SQLString("Offer_48_80").ToDouble()
.Offer_48_120 = _SQL.Reader.SQLString("Offer_48_120").ToDouble()
If .Offer_24_20 = -1 Then
.Rental_24_20 = 0
ElseIf .Offer_24_20 > 0 Then
.Rental_24_20 = .Offer_24_20
Else
.Rental_24_20 = _SQL.Reader.SQLString("Rental_24_20").ToDouble()
End If
If .Offer_24_40 = -1 Then
.Rental_24_40 = 0
ElseIf .Offer_24_40 > 0 Then
.Rental_24_40 = .Offer_24_40
Else
.Rental_24_40 = _SQL.Reader.SQLString("Rental_24_40").ToDouble()
End If
If .Offer_24_60 = -1 Then
.Rental_24_60 = 0
ElseIf .Offer_24_60 > 0 Then
.Rental_24_60 = .Offer_24_60
Else
.Rental_24_60 = _SQL.Reader.SQLString("Rental_24_60").ToDouble()
End If
If .Offer_36_30 = -1 Then
.Rental_36_30 = 0
ElseIf .Offer_36_30 > 0 Then
.Rental_36_30 = .Offer_36_30
Else
.Rental_36_30 = _SQL.Reader.SQLString("Rental_36_30").ToDouble()
End If
If .Offer_36_60 = -1 Then
.Rental_36_60 = 0
ElseIf .Offer_36_60 > 0 Then
.Rental_36_60 = .Offer_36_60
Else
.Rental_36_60 = _SQL.Reader.SQLString("Rental_36_60").ToDouble()
End If
If .Offer_36_90 = -1 Then
.Rental_36_90 = 0
ElseIf .Offer_36_90 > 0 Then
.Rental_36_90 = .Offer_36_90
Else
.Rental_36_90 = _SQL.Reader.SQLString("Rental_36_90").ToDouble()
End If
If .Offer_48_40 = -1 Then
.Rental_48_40 = 0
ElseIf .Offer_48_40 > 0 Then
.Rental_48_40 = .Offer_48_40
Else
.Rental_48_40 = _SQL.Reader.SQLString("Rental_48_40").ToDouble()
End If
If .Offer_48_80 = -1 Then
.Rental_48_80 = 0
ElseIf .Offer_48_80 > 0 Then
.Rental_48_80 = .Offer_48_80
Else
.Rental_48_80 = _SQL.Reader.SQLString("Rental_48_80").ToDouble()
End If
If .Offer_48_120 = -1 Then
.Rental_48_120 = 0
ElseIf .Offer_48_120 > 0 Then
.Rental_48_120 = .Offer_48_120
Else
.Rental_48_120 = _SQL.Reader.SQLString("Rental_48_120").ToDouble()
End If
End With
Else
_Vehicle = Nothing
End If
Else
_Vehicle = Nothing
End If
_SQL.DisconnectReader()
Catch
_Vehicle = Nothing
End Try
Return _Vehicle
End Function
Public Function Vehicle(ByVal SearchText As String) As Data.LeasingPrices.Vehicle
Dim _Vehicle As New Data.LeasingPrices.Vehicle
_Vehicle = GetVehicle(Hydrate.SearchBy.Derivative, SearchText)
If _Vehicle Is Nothing Then
_Vehicle = GetVehicle(Hydrate.SearchBy.Model, SearchText)
End If
If _Vehicle Is Nothing Then
_Vehicle = GetVehicle(Hydrate.SearchBy.Make, SearchText)
End If
Return _Vehicle
End Function
Private Function GetSearchOption(ByVal SearchOption As String) As String
Dim _GetSearchOption As String = ""
Try
If Not HttpContext.Current.Session(SearchOption) Is Nothing Then _
_GetSearchOption = HttpContext.Current.Session(SearchOption)
Catch
_GetSearchOption = ""
End Try
Return _GetSearchOption
End Function
Public Function SearchOptions() As Data.LeasingPrices.SearchOptions
Dim _SearchOptions As New Data.LeasingPrices.SearchOptions
Try
With _SearchOptions
.FourByFour = GetSearchOption("FourByFour").ToBoolean()
.CityCar = GetSearchOption("CityCar").ToBoolean()
.Coupe = GetSearchOption("Coupe").ToBoolean()
.Estate = GetSearchOption("Estate").ToBoolean()
.Hatchback = GetSearchOption("Hatchback").ToBoolean()
.MPV = GetSearchOption("MPV").ToBoolean()
.Saloon = GetSearchOption("Saloon").ToBoolean()
.Sports = GetSearchOption("Sports").ToBoolean()
.Van = GetSearchOption("Van").ToBoolean()
.RentalFrom = GetSearchOption("RentalFrom").ToInteger()
.RentalTo = GetSearchOption("RentalTo").ToInteger()
If .RentalFrom = 0 And .RentalTo = 0 Then
.RentalFrom = Data.LeasingPrices.SearchOptions.DefaultRentalFrom
.RentalTo = Data.LeasingPrices.SearchOptions.DefaultRentalTo
End If
End With
Catch
_SearchOptions = Nothing
End Try
Return _SearchOptions
End Function
#End Region
#Region "Constructors"
Public Sub New()
End Sub
#End Region
End Class
End Namespace
I'm not familiar with the Net.SQL entity you're using, but it is usual to use something like the Convert.IsDBNull Method to check for a NULL database value.
An alternative is to use COALESCE in the query, like
SELECT TOP 1 [CVehicleId], ..more columns.., COALESCE([ImageId], 'AwaitingImage'), ..remaining columns..
You should really explicitly specify the columns, and put the column names in square brackets so that if you accidentally have a column name which happens to be an SQL keyword then it doesn't mistake it for a keyword.

How to check a value is already in a grid?

Using the following to add values from a combobox and textbox into a grid.
Dim pdt, pdtid As String
Dim i As Integer
pdt = cboProducts.Columns(0).Text
pdtid = cboProducts.Columns(1).Text.ToString
If grdSale.Rows.Count = 0 Then
i = 0
Else
i = i + grdSale.Rows.Count
End If
grdSale.AddRows(1)
grdSale(i, 1) = pdt
grdSale(i, 0) = pdtid
grdSale(i, 3) = txtQty.Text
grdSale.Splits(0).DisplayColumns(0).Visible = False
So how can I check duplicates in grid, i.e if I enter a product that is already in the grid then I need to show a warning message?

ZedGraph - Force all graph panes to be the same size

I am using the ZedGraph control (zgc) to create individual stacked bar charts and display them in a single stacked column as shown in the image below.
The issue that I am having is that I have no control over the number of panes that are displayed in the control as this is determined by the number of items in a listbox. It seems that the default nature of the control allows the height of the graph panes to change depending on the number of panes that are displayed within the control.
The zgc is set to dock=fill within a panel control that is set to dock=fill within the form. I would like to force the graph panes to be a static height and when needed have a vertical scroll bar appear in the panel when the number of graph panes exceeds the height of the form. How can I go about achieving this? My code for creating and populating the zgc is posted below the image.
Private Sub CreateGraph(ByVal dat As Date)
Dim count As Integer = 0
Dim master As MasterPane = zgc.MasterPane
master.Fill = New Fill(Color.FromArgb(180, 180, 180), Color.FromArgb(180, 180, 180), 45.0F)
master.PaneList.Clear()
master.Title.IsVisible = True
master.Title.Text = "Workload for " & dat.ToShortDateString()
master.Margin.All = 10
master.InnerPaneGap = 5
master.IsCommonScaleFactor = False
For Each mach As String In lbMach.Items
rowCount = 0
Dim myPaneT As New GraphPane(New Rectangle(10, 10, 10, 10), "", "Time in Minutes", mach)
myPaneT.Fill.IsVisible = False
myPaneT.Chart.Fill = New Fill(Color.White, Color.White, 45.0F)
myPaneT.BaseDimension = 3.0F
myPaneT.XAxis.Title.IsVisible = False
myPaneT.XAxis.Scale.IsVisible = False
myPaneT.XAxis.Scale.Min = 0
myPaneT.XAxis.Scale.Max = (MeiSettings.WrkHrs * 60)
myPaneT.Legend.IsVisible = True
myPaneT.Border.IsVisible = False
myPaneT.Title.IsVisible = False
myPaneT.XAxis.MajorTic.IsOutside = False
myPaneT.XAxis.MinorTic.IsOutside = False
myPaneT.XAxis.MajorGrid.IsVisible = True
myPaneT.XAxis.MinorGrid.IsVisible = True
myPaneT.Margin.All = 1
If count = lbMach.Items.Count - 1 Then
myPaneT.XAxis.Title.IsVisible = True
myPaneT.XAxis.Scale.IsVisible = True
myPaneT.Margin.Bottom = 10
End If
If count > 0 Then
myPaneT.YAxis.Scale.IsSkipLastLabel = True
End If
myPaneT.YAxis.MinSpace = 20
myPaneT.Y2Axis.MinSpace = 20
Dim dt As DataTable = ItemsByMachineDT(mach, dat)
Dim myCurve As BarItem
If dt.Rows.Count > 0 Then
Dim profName As String = Nothing
Dim timeDur() As Double
For Each dr As DataRow In dt.Rows
If profName = dr("PRO").ToString() Then
timeDur = {((Convert.ToDouble(dr("QTY")) / Convert.ToDouble(dr("MPM"))))}
Else
timeDur = {((Convert.ToDouble(dr("QTY")) / Convert.ToDouble(dr("MPM")) + Convert.ToDouble(dr("Time"))))}
End If
myCurve = myPaneT.AddBar(dr("JOB").ToString & " - " & dr("PRO").ToString(), timeDur, Nothing, BarColor(rowCount))
If MeiSettings.IsGradient = True Then
myCurve.Bar.Fill = New Fill(BarColor(rowCount), Color.White, BarColor(rowCount), 90.0F)
Else
myCurve.Bar.Fill = New Fill(BarColor(rowCount), BarColor(rowCount), BarColor(rowCount), 90.0F)
End If
rowCount += 1
profName = dr("PRO").ToString()
Next
End If
myPaneT.YAxis.MajorTic.IsBetweenLabels = True
myPaneT.YAxis.Type = AxisType.Text
myPaneT.BarSettings.Type = BarType.Stack
myPaneT.BarSettings.Base = BarBase.Y
master.Add(myPaneT)
count += 1
Next
zgc.IsShowPointValues = True
Using g As Graphics = Me.CreateGraphics()
master.SetLayout(g, PaneLayout.SingleColumn)
master.AxisChange(g)
End Using
End Sub
to get control for each GraphPane :
GraphPane temp = zgc.MasterPane.PaneList.ElementAt(ind); //ind => index of the graphpane in zedgraphcontrol
to set static height n width ZedgraphControl :
zgc.Size = new Size(Width,Height);
to set visibility of scrollbar ZedgraphControl :
zgc.IsShowHScrollBar = true;
zgc.IsShowVScrollBar = true;