display current row dataGridView in c# - indexing

what is the difference between these codes?
a.textBox3.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["price"].Value.ToString();
a.textBox3.Text = dataGridView1.CurrentRow.Cells["price"].Value.ToString();
the output of codes is same but I can not understand the difference.

Related

Check one series value, change corresponding point colour in 2nd series

I have an automated pareto chart working well in Excel.
I want to change it to check if points in the cumulative percentage series have a value of less than 80% and colour the same number point in the count series if this is the case.
Tried this; doesn't throw any errors but also doesn't work.
I think it should be iterating through a list of values, checking if they are <80 then updating the point at the corresponding i in the count series.
Set percVals = paretoChart.Chart.SeriesCollection(percentSeries).Values
For Each i in percVals
If percVals(i) = <80 Then
With paretoChart.Chart.SeriesCollection(countSeries).Points(i)
.Format.Fill.ForeColor.RGB = RGB(0,0,225)
.Format.Line.ForeColor.RGB = RGB(0,0,225)
End With
End If
Next i
The "paretoChart" variable is set earlier in the code and is working fine throughout.
I've tried without the 'with' statement. No difference.
There is a similar question comparing the two values across series, but I don't think I can adapt that to work here. Any ideas appreciated!

DataGridView Prevent Formatting

Hello again I am trying to get the value of a Cell in DGV (datagridview)
but i noticed it was returning a truncated an Rounded up Value.
Value in Cell = 32.71529844248667
but Returned Value = 32.7152984424867
the code i am using
Dim data As String = DGV.Item("latitude", DGV.CurrentRow.Index).Value
MsgBox(data)
Cant seem to be able to fix it even by setting formatting to none. Any ideas or can you point me in right direction? Thank you in advance!

How do I get more information from an additional column if the first one does not have it?

I would just like to say that I'm very new to VBA and more complicated formulas so all the help will be appreciated! Thank you!
To clarify a bit more with the title. I currently have a Macro that is reading a formula to give me information from another worksheet. I'll give an example of the formula that is working:
=IF(A2 = ""No Specific Program"", A2,IF(F2 = """",""No PIN"",IFERROR(VLOOKUP(CONCATENATE(A2,F2),....!$C:$I,4,FALSE),""NO DATA"")))
This is the original formula that I'm using to get the information, column A is my Parts owned by Program, And my column B is the actual Program. So when I run the Macro it does give me most of the information, but when it runs into "No Specific Program" even when there is something for Column B showing what program the part is in, it will give me No specific Program.
Also for reference the F2 it is Concatenating is a PIN number which will help determine who owns the part.
I've been stumped on this trying to get the code to work and I've tried place THEN and ELSE within the statement and it just gives a FALSE statement
EDIT:
The Code above works, it's when I use this version of the Code:
=IF(A2 = ""No Specific Program"",THEN,IF(F2 = """",""No PIN"",IFERROR(VLOOKUP(CONCATENATE(A2,F2),'.....'!$C:$I,4,FALSE),""NO DATA"",Else,IF(A2 = ""No Specific Program"",THEN,IF(F2 = """",""No PIN"",IFERROR(VLOOKUP(CONCATENATE(A2,F2),'.....'!$C:$I,4,FALSE),""NO DATA"")))))
I get the False or errors when I try different variations. Here is an example of the columns. Column A is where I have the original formula reading from, but then it says No Specific Program, while Column B shows the Program. So I'm trying to get the formula to read that as well as column A to capture all the information I need :
Columns Example
EDIT:
It starts breaking after the ELSE statement.
Edit:
=IF(A2 = ""No Specific Program"",
IF(F2 = """",""No PIN"",IFERROR(VLOOKUP(CONCATENATE(B2,F2),'\NW\Data\TechIntegration\Sustaining
Team\Data
Mining\DataMining[GAD_PIN_TABLE.xlsx]Sheet1'!$C:$I,5,FALSE),
""NO GAD
DATA"",
IF(F2 = """",""No
PIN"",IFERROR(VLOOKUP(CONCATENATE(A2,F2),'\NW\Data\TechIntegration\Sustaining
Team\Data
Mining\DataMining[GAD_PIN_TABLE.xlsx]Sheet1'!$C:$I,5,FALSE),""NO GAD
DATA"")))))
Just trying to make it easier to see the formula.
I'd split this down to make it simpler to follow, use a holding cell then refer to that in your top formula (The one you know works already)
Stick this in another column, say Z for example, then everywhere you refer to A2 in your working formula, change it to Z2
=IF(A2=""No Specific Program"",IF(B2=""No Specific Program"",""No Specific Program"",B2),A2)
This will only give you "No specific program" if both a2 and b2 contain "No specific program" which I think is what you're after. In your second example in the columns example link, it will return NG

VB.NET CHART- Display a subset of the total data points

VB 2008
.NET FRAMEWORK 3.5
MSCHART - FASTLINE CHART TYPE
Is it possible to have an MS Chart control contain 20,000 data points, but only show the last 100?
I know that I can select the last 100 from my datatable and use it as a datasource.
Chart1.DataSource = cMs2.dsData.Tables("readings").Select(wFilter, wSort).Take(100)
That's not what I want.
I know that I can populate an array or collection with the last 100 data points and use it as a data source.
Chart1.Series("readings").Points.DataBindXY(colCtr, colReadings)
That's not what I want.
I need to do 1 of 2 things:
Manually add data points and be able to show only the last 100 or last 1000 of them that just came in. This must be done without re-populating the chart. Just show a portion of the complete set of data points.
wSample = wSample + 1
Chart1.Series("readings").Points.AddXY(wSample, wReading)
Chart1.Series("readings").SHOWONLYTHELAST100DATAPOINTSWITHOUTCLEARING
Initialize a chart with a certain number of the total readings with a databind, then manually add new data points one at a time while removing the oldest data point. For example, initialize the chart with 100 data points, then add a new data point, remove the first data point, getting us back to 100. (I'm successfully doing this one, except the chart doesn't behave like I expect. The chart grows, remaining blank/empty where the 'removed' data points were. I do chart.update but it doesn't refresh it.) Note that I am allowed to take more time to initialize the chart (clear/populate), I don't have that time to do it as each new data point comes in.
wSample = wSample + 1
Chart1.Series("readings").Points.AddXY(wSample, wReading)
If Chart1.Series("readings").Points.Count > 100 Then
Chart1.Series("readings").Points.RemoveAt(0)
Chart1.Update()
End If
NOTE: Doing a process that causes me to have to clear and rebind the data to handle the addition of a single data point causes me problems because it takes too long. I'm just looking for the quickest, most efficient way to handle this. Thank you for taking the time to read this...!
You can manually set the Minimum and Maximum values of each axis by modifying the .Minimum and .Maximum values of the axes like
Chart1.ChartAreas(0).AxisX.Minimum = 100 'Example value
Chart1.ChartAreas(0).AxisX.Minimum = 200 'Example value
As discussed in the comments to your question you can either use your method #2 (add datapoint and delete datapoint index 0 and then select the new minimum and maximum X-Value from the series with LinQ:
Chart1.ChartAreas(0).AxisX.Minimum = (From p As DataVisualization.Charting.DataPoint In Chart1.Series(0).Points Select p.XValue).Min
Chart1.ChartAreas(0).AxisX.Maximum = (From p As DataVisualization.Charting.DataPoint In Chart1.Series(0).Points Select p.XValue).Max
or you can, as you have now done, just set the minimum value to a X-value some points before the last point.

ListBox or Combobox ADODB imported Decimal items invisible in the list

I have encountered this problem several times already and have been able to work around it till now. Also the almighty search engines didn't help me.
The problem is that when I have populated a listbox or combobox from a ADODB recordset all Decimal data elements are not visible in the box, for example with the following (conn is a ADODB connection):
Private Sub GetFilteredRecords()
Dim strSQL As String
Dim arr As Variant
'create the SQL
strSQL = "SELECT * FROM vwStandard_Fee2"
'execute the SQL and fill the rs ( rsFiltered )
Set rsFiltered = conn.Execute(strSQL)
'Apply recordset to the listbox on the form
If Not (rsFiltered.EOF = True And rsFiltered.BOF = True) Then
arr = rsFiltered.GetRows()
With lbDeeper
.ColumnCount = rsFiltered.Fields.Count
.List = TransposeArray(arr)
End With
With cbDeeper
.ColumnCount = rsFiltered.Fields.Count
.List = TransposeArray(arr)
End With
End If
End Sub
Above contains 6 columns of Ids (all show Type = Variant/Decimal), of which the containing values are all not "shown" for some strange reason. Only the String and Date columns are shown normally, the Decimals are there but empty!
Here some snippets:
Now in case of a combo box I can get one column's value shown if their column the BoundColumn when I select that listitem, but only in the value fo the combobox (so still not in the list).
My initial workaround was to convert them into String values before adding to the Listbox/Combobox, in this case however I want to directly link the query result to the Box.List without looking at the details. And thus I am looking for a solution in stead of a work around.
In short: my numerical field items are invisible BY DEFAULT for some strange reason. Workaround was to make the items String values. I am now looking for a solution for this bug/problem instead:
What is causing this?
How to solve it?
So all string data is appearing? And,only numerics don't appear?
Then you may want to convert your numerics to strings and pass it to your list, combo boxes.
Which you have already done I noticed.
Now for any reason if your max number of rows and length of array/recorders row count doesn't match it could also cause an issue. However it seems your setting rows of combobox using recordset row count. Instead of using an array can you try to iterate over the recordset to populate the combobox? yes this is not performance friendly, buy guess what we need it to work without bugs before optimizing. ;-)
Have you bound your combobox to the recordset? Can you confirm if your array is single dimension and it has data to feed to the box?
You may try to populate the listbox using a saved query in the DB to if the issue still persists.
However, list boxes and combo boxes based on SQL statements are slower than
list boxes and combo boxes based on saved queries.
So can you try the following to set rowsource property? Make sure to test on both number,and test columns. As well as on old combo box and new one.
Rowsource->build query->
sqlview copy to rowsource property box->
delete or don't save that above built query since you already have SQL statement.
Just wanted you to try out possibilities to narrow down the issue.
UPDATING ANSWER WITH MOST POSSIBLE ISSUE AND SOLUTIONS
As per my comments, they mainly given assuming you had issues populating listbox/combobox
I forgot to ask something very very important, have you declared
Option Base 1 to make sure to avoid losing one of the array's column
values if you are dumping 2D array...? because you do not have any
explicit declartion for the array you are using to dump data into the
listbox.......... :)
Make sure your Listbox is enabled to show multi column data.
*So you have three choices, *
Option Base 1
ReDim your array and do looping to fill it and dump it into .list.
Since ReDim array need you to anyway loop through, you may just as well
use the recorset iself to add the data.
You seem to have a dimension issue with the array which is not declared but transposed from recordset and then to listbox/combobox. So your undeclared array is not populating multi-columns properly. That could be the reason it works when you declare array proeprly.......
Infact in your comment you have said so,
When I create an array in my code and populate it in my code (entry by
entry) it will show without any problem – K_B 14 mins ago
OK after going through various possible causes it seems to be the case that:
VBA has no Decimal Variant Type of its own.
VBA can handle Decimal from within a variable declared as Variant (thus becoming a Variant/Decimal)
This normally doesn't stop your program from working, but in Controls like Listbox and Combobox the Type Variant/Decimal is not interpretable and thus wont draw that specific entry.
For example populate a listbox called lbHigher with this:
Private Sub ListBoxProblem()
Dim tempArray(2, 2) As Variant
tempArray(0, 0) = "A"
tempArray(0, 1) = 1
tempArray(0, 2) = 1.1
tempArray(1, 0) = "B"
tempArray(1, 1) = CStr(CDec(5.2))
tempArray(1, 2) = 2.3
tempArray(2, 0) = "C"
tempArray(2, 1) = DateSerial(2012, 12, 13)
tempArray(2, 2) = 100
tempArray(3, 0) = "D"
tempArray(3, 1) = -1
tempArray(3, 2) = CDec(5.2)
lbHigher.ColumnCount = 3
lbHigher.List = tempArray
End Sub
Everything works fine except for the CDec(5.2). The CStr(CDec(5.2)) works fine as well as VBA will first have converted the Decimal to String before the Listbox gets to get it.
So either: Dont let the SQL generate any Decimal output OR convert any Decimal output to Single/Double/String/Integer/Long in VBA before handing it to the Listbox.