i can't fill my gridview vb.net - 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.

Related

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

Color Grid in Excel by vb.NET

I need some help.
What I need is a code for colorid the Grid in Excel in this way:
find the first cell with value ( 1 )
find the last cell with value ( 2 )
range (1:2)
Color the grid black
My code by now:
'Color the columns A to K and ALL the rows below, no matter if they have a value or not.
xlWorkSheet.Range(xlWorkSheet.Cells(1, 1), xlWorkSheet.Cells(xlWorkSheet.Rows.Count, 11)).Borders.ColorIndex = 0
I need to change the color of not-empty rows .
THX
Find the first cell :
You should active the first cell (A1) and use IsEmpty function.
Then you loop in the same column until you find a cell containing a value.
By the way, you need to keep the number of this row for the second point.
Find the last cell :
You have to exit your loop when it finds a new empty row. Then you'll get the range of cells using the number of first and last row.
You can check the MSDN - "Empty Cells" to get more details.

How to have values from 3 columns shown in combobox VBA (active x control)

In combobox I set columnCount to 3, so when I click dropdown arrow I can see 3 columns that I need, but when I choose one row that I need, there is only value from first column shown. Combobox is wide enough for all three columns. Is there a way to see all 3 when I select my choice?
You need to change the ListFillRange to all the columns in your list:
Sheet1!$A$5:C20
Also you need to have a single cell referenced in the LinkedCell property: Sheet1!$A$1
The bound column must be a value between 1 and 3. You can only return a single value from the list - this will be from the bound column.
Your column count must be 3.
Your column widths must be either blank or a value >0 (0 will hide the column):
85.05 pt;85.05 pt;85.05 pt
With those in place you should be seeing three columns of values in the list box - you can only return a value from one of those columns though.
If you want to return more than one I'd suggest using a hidden (column width of 0) column to contain a unique identifier and then use a look-up on the sheet to fill in the blank columns.
To get to all three columns in VBA use code similar to:
Private Sub ComboBox1_Change()
With Me.ComboBox1
MsgBox .Column(0) & vbCr & .Column(1) & vbCr & .Column(2)
End With
End Sub

Multi-Column ComboBox in Excel VB

I have some ComboBoxes in a UserForm. One of the ComboBoxes is a multicolumn ComboBox with three columns and is dependent on another ComboBoxs' value.
Does anyone know WHY when I choose one of the lines in the multicolumn combobox shows only the first column value?
I want the value from the second column to be visible when I choose a line.
The Combox Property that set which column to display in the TextBox portion of the Combobox is TextColumn
Property values:
-1 = Display the first column whose width (set by ColumnWidths property) is > 0
0 = Display the value of ListIndex
1 = Display column 1
etc

Devexpress LookupEdit is not displaying the selected row for the last row

I am using DevExpress.XtraEditors.LookUpEdit to display the information about the classes available. Currently it has 3 columns. The lookupedit is working perfectly except when I set the editValue to the last row. When the editvalue is set to any row other than the last one it shows the selected row when the lookupedit isn't opened yet when the lookupedit is set to the last row nothing is displayed. Currently I am :
lookupedit.Properties.ForceInitialize() ' Force it to initialize
lookupedit.Properties.PopulateColumns() ' Force the lookupedit to populate
For i As Integer = 0 To tableData.Rows.Count - 1 ' Go through the information in it
If lblClassVal.Text = tableData.Rows(i).Item(1).ToString() Then ' if the current row is equal to the value I want to select
lookupedit.EditValue = i + 1 ' then I set the lookupedit value
End If
Next i
lookupedit.Properties.Columns("class_id").Visible = False ' set two columns to invisible
lookupedit.Properties.Columns("active").Visible = False
lookupedit.Properties.Columns("class_name").Caption = "Class Name" ' set the 3rd column to a better title
Right now the lookupedit displays the selected text unless I select the last row, row number tableData.Rows.Count which then displays nothing. Yet when I print the values they are correct and when I remove the +1 when setting the lookupedit it sets it to the previous line I want an the first row can't be displayed.
Ok I solved this. Just in case someone else if having this problem I will leave the question up.
So the DevExpress LookUpEdit doesn't use the row number, it uses the ID column in your LookUpEdit table. So instead of selecting this by the row number set the EditValue to the ID number of the row you want to select. So instead of:
If lblClassVal.Text = tableData.Rows(i).Item(1).ToString() Then ' if the current row is equal to the value I want to select
lookupedit.EditValue = i + 1 ' then I set the lookupedit value
End If
Use :
If lblClassVal.Text = tableData.Rows(i).Item(1).ToString() Then ' if the current row is equal to the value I want to select
lookupedit.EditValue = tableData.Rows(i).Item(0).ToString() ' Where Item(0) is my ID number column
End If