DefaultCellStyle.Format not working after data entry in cell - vb.net

I have two columns that I want formatted as "N2". However the one that is set to read only and on displays info works fine while the other column that allows data to be entered does not format the data after the user enters it.
account_grid.Columns.Item(3).DefaultCellStyle.Format = "N2"
account_grid.Columns.Item(4).DefaultCellStyle.Format = vbShortDate
account_grid.Columns.Item(8).DefaultCellStyle.Format = "N2"
Column 3 works fine and get populated with data when the grid is loaded. The data is formatted correctly (as N2).
Column 8 is empty to start and allows uses to enter data. After a users enters a number (for example 25678), I want the number format to change to 25,678. But it is not changing.
This is the code that populates the grid:
For x As Integer = 0 To account_list.Count - 1
account_grid.Rows.Add(account_list(x)(0), account_list(x)(1), account_list(x)(2)...[to 8])
Next

Related

Copy data from DataGrid View to another B

I want to copy data from DataGrid View to another, as follows
The second DataGrid View contains 8 columns, they are actually a duplicate of the first DataGrid, but in order for the data to be grouped next to some
What do I want to collect data from the first DataGrid View by the second so that the columns that start inside the first column with the letter A in the first DataGrid View, which bears the symbol B in the second part of the DataGrid View 2, have the same name as it
And it becomes the final shape with the knowledge that the columns of the letter A can be more or vice versa, but the request is the same as collecting data next to some, even if some fields appear empty when the fields between A, B are not equal.
For ii = 0 To DATAG_CLIENT.Rows.Count - 1
If DATAG_CLIENT.Rows(ii).Cells(0).Value.ToString.Contains("A") Then
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(0).Value = DATAG_CLIENT.Rows(ii).Cells(2).Value
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(1).Value = DATAG_CLIENT.Rows(ii).Cells(3).Value
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(2).Value = DATAG_CLIENT.Rows(ii).Cells(4).Value
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(3).Value = DATAG_CLIENT.Rows(ii).Cells(5).Value
End If
If DATAG_CLIENT.Rows(ii).Cells(0).Value.ToString.Contains("B") Then
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(4).Value = DATAG_CLIENT.Rows(ii).Cells(2).Value
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(5).Value = DATAG_CLIENT.Rows(ii).Cells(3).Value
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(6).Value = DATAG_CLIENT.Rows(ii).Cells(4).Value
PRINTSHOW.DATGR_PRINT.Rows(ii).Cells(7).Value = DATAG_CLIENT.Rows(ii).Cells(5).Value
End If
Next 'BAD RESULT

Yes/No data type always displaying as True/False - Boolean formatting issues

I have several fields on a form that absolutely will not display a boolean value which is set to display as Yes/No, the dropdown menu is set to only offer Yes/No as options, but no matter what I do, the values displayed on the form always show True/False instead. Pictures below:
At this point I'm not entirely sure what it is that's causing this, but it's kind of annoying.
If you want to use a ComboBox, set the ComboBox properties as follows
In the data section:
Control Source = <name of your table or query column>
Row Source Type = Value List
Row Source = -1;Yes;0;No ' Alternating values and texts.
Bound Column = 1
Limit To List = Yes
In the format section
Column Count = 2 ' Because we have a value and a text.
Column Widths = 0cm ' This makes the first column invisible.

VBA - How to refer to column names in Array?

To start, I have a scraping function that scrapes a table from a web page, and stores the data in a 2D array.
The 2D array starts from row 0 to however many rows of data are on the page, and columns 1 to however many columns there are.
Row 0 simply contains all the column names.
My ReDim:
ReDim Addresses(0 To lngTotalRecords, 1 To columns.Count) As String
I've then stored this 2D array into a scripting dictionary called dictClients, as there are multiple clients that all have their own entries for the same table on the web page.
So in my dictionary I have something like the following to refer to a particular address table for a particular client:
dictClients(1)("Addresses")
dictClients(2)("Addresses")
I now want to be able to check if a cell in a certain row contains a specific value, however the web page allows the columns to be reorganized so that:
dictClients(1)("Addresses")(1,1) 'row 1 column 1
will not always refer to the "Street Number" column. The street number column could be the following for someone else for example:
dictClients(1)("Addresses")(1,3) ' row 1 column 3
Given that these cells:
dictClients(1)("Addresses")(0,1) '(0,2) (0,3) etc.
all refer to the column's names, what's the best way for me to find the position of a particular named column?
Example: I want to get the value of the Postal Code cell in row 1, so I need to look in
dictClients(1)("Addresses")(1, POSTALCODECOLUMN),
which isn't always in the same position on the web page.
I was thinking of using the following function:
Public Function column(strArr() As String, strColumnName As String)
Dim i As Long
For i = 1 To UBound(strArr, 2)
If strArr(0, i) = strColumnName Then column = i
Next
End Function
But it just feels so lengthy calling it like:
strPostalCode =
dictClients(1)("Addresses")(1,column(dictClients(1)("Addresses"), "Postal Code")
Is there a better and easier way to do this?
Thanks.

i can't fill my gridview vb.net

In my project , i have 2 windows forms and 1 gridview contains 5 columns (name gridv)
I want to fill 4 columns from forms1 and the 5th columun from the forms2
but i can't do it (error in my appli execution )
my code (how to fill the 5th column)
Dim selectrow As Integer = Form1.gridv.CurrentRow.Index ' selectrow mean selected row indice
MessageBox.Show("ligne selectionnée : " & Convert.ToDouble(selectrow))
Form1.gridv.Rows.Add(corp_mail.Text = Form1.gridv.Item(4, selectrow).Value) ' fill the 5th column`
You haven't shown the error but from what information you have given this is what your code is doing:
evaluates if corp_mail.Text is equal to the value of the 5th column of the selected row. This is a true or false, not a string.
Adds (or tries to) a new row to the grid with true or false as the value of the first cell.
If I understand correctly, this is what you want to do:
Form1.gridv.Item(4, selectrow).Value = corp_mail.Text
This will set the value of the 5th column of the selected row.
Although you mention a second grid on another form, not a textbox, so you probably have more work to do. But the idea is the same, instead of the TextBox value get the value from the other grid.

Gridview compare to list and set value to gridview checkbox

I have a grid view which has 3000 rows and one checkbox column and 2 textbox column.
I have a parameter list around say around 1700. it varies sometimes 5 or 10.
So I need to compare the list to the grid view and set the 1st checkbox column to true.
I use the compare and select method like below code which works well for a small number of parameter like 50,70
If Paramlist.Count > 0 Then
Dim row As Integer = 0
For Each listItem In Paramlist
Do While (row < gridview1.RowCount)
If Trim(gridview1.Rows(row).Cells(1).Value) = Trim(listItem) Then
gridview1.Rows(row).Cells(0).Value = True
Exit Do
End If
row = row + 1
Loop
Next
End If
It takes a lot of time to compare and set gridCheckbox value to true when I do it with more parameter list and the application seems like it is hanging when the user uses it.
Could anyone suggest me a faster way with less time complexity / best practice to set the grid check box value to true in the grid view.
[UPDATE]
I have attached a image of the exception thrown.
System.Invocation.TargetInvocationException