DataGridView and Combobox Column? - vb.net

when DataGridView has a combobox column, how can I get the text it displays as oppose to the value it represents? When I do DGV.Item("cbo",i).Value I get the value but it won't take DGV.Item("cbo",i).Text. I trying Ctype(DGV.Item("cbo",i),ComboBox).Text and this does not work either.

Try
DGV.item("cbo",i).DisplayMember

Umm are you talking about Win Forms?
If so, Value is the property you want, and is what is to be displayed on the screen and held behind the scenes.
If you want something different not shown to the user, I've often used the property Tag for that.

I found this, and the answers didn't work for me. In case someone else finds this, here is what I did.
dgv.rows(i).Cells(cboname.index).EditedFormattedValue
Hope if someone finds this through Google it will help them.

Dim dgvcmbcell As DataGridViewComboBoxCell = DgvItemsUnits.Item("UNIT_SER", 0)
Dim SelectedText As String = dgvcmbcell.EditedFormattedValue.ToString()

Related

Scroll FlowPanel scrollbar with a Trackbar

I have a FlowLayoutPanel1 in my form with a bunch of buttons inside it. I wanted to change the way its scroll bar looked so I added a TrackBar1 hoping to make it look better. I can't figure out how to do it.
I tried:
Panel1.AutoScroll.value = TrackBar1.Value
But it gives the error:
'value' is not a member of Boolean
What have I done wrong in this code?
Your code is wrong. Change it to
Panel1.HorizontalScroll.Value = TrackBar1.Value
Here, Panel1.AutoScroll only tells you if it's True or False.
I got it guys. I should've put .VerticalScroll.Value instead of AutoScroll.Value.
Panel1.VerticalScroll.Value = TrackBar1.Value
This worked.
As others have already mentioned, Panel1.AutoScroll is a boolean. You need to use HorizontalScroll.Value or VerticalScroll.Value whichever matches your requirement.

How to allow a combobox to be left blank//skipped on a form

I am relatively new to Access and any SQL and VBA I have picked up is self-taught, so I would really appreciate answers that are not too heavily laden with technical terms...that said, I am having an issue with allowing comboboxes to be left blank on a form if the user chooses not to input data. Also, I am using Access 2016.
Initially the problem I ran into was that if a combobox was entirely skipped and left blank, or if the user selects the combobox and then tries to move on without making a selection from the list, they got the error "You tried to assign the Null value to a variable that is not a Variant data type," and were unable to move on to any other fields on the form or to save the record being entered.
I found this article that details a possible solution, but I can't seem to get it to work. I made an unbound combobox, set the Row Source to:
SELECT EmailID, PersonalEmail FROM EmailT UNION SELECT "<N/A>","<N/A>" FROM EmailT
ORDER BY PersonalEmail;
where PersonalEmail is a field of type short text and the EmailID is an autonumber. I also followed the article's steps for formatting the combobox (column width, etc.) and set it to Limit to List = Yes.
Here is my exact code:
Private Sub Combo62_AfterUpdate()
If Combo62 = "<N/A>" Then
EmailID = Null
Else
EmailID = Combo62
End If
End Sub
Private Sub Form_Current()
If IsNull(EmailID) Then
Combo62 = "<N/A>"
Else
Combo62 = EmailID
End If
End Sub
< N/A> now shows up on my list, but if it is selected I get the error: "The value you entered isn't valid for this field. For example, you may have entered text in a numeric field or a number that is larger than the FieldSize setting permits."
Access's debugger highlights the line:
EmailID = Null
but I am not sure what steps I should take now to try and fix this.
I am completely open to other methods of allowing the combobox to be left blank if someone knows of a better way to do this also. For all I know, I am missing something really obvious! Thanks in advance for any insight!
EDIT: Thanks for your help guys, I never did figure out what exactly the problem was, but I got some advice from another forum to rethink my database design so this ended up being a null issue--it's all totally different now!
If the recordsource for your form contains a query with one-to-many relationships this error may come up. Try to use only the base table as the recordsource for the form. Use subforms if you need to display related data. The rest of the code may then be unnecessary.

How to lock combobox so that the text and items cannot be modified/delete/erased?

Is it possible lock the combobox so that the text can not be deleted/erased or modified. And make only choose the items? Thank you in advance. Hope is it possible.
Set the "DropDownStyle" property of the combobox to DropDownList.
This will allow only items in the list to be selected and will not allow any user input:
Option 1
Simply set the ComboBox.Enabled to False - that way they can't change the values!
Option 2
Otherwise, use the dropDownStyle:
make DropDownStyle property to DropDownList instead of DropDown
For more information
Read this article (yes, it's written in c#, but the properties are the same!)
the above image displays this quite well.
EDIT
There is also a question previously asked here that asked a similar question.
You can set ComboBox.DropDownStyle to ComboBoxStyle.DropDownList.

Searching for specific data in datagridview

I have to work on a project that has a datagridview without a datasource. Also it's done in vb.net. I want to loop through each row on a specific column to find specific data and set my focus on that record.
For Each item As C1.Win.C1FlexGrid.Row In myDataGrid.Rows
' something like searchFor/contains
' (no idea, can't find the right way to search) for mySpecificData
Next
Help is appreciated, best regards
I assume that you are using component One FlexGrid, so I had a look at the documentation at the according site. Each row has an Item Property so this example might work
For Each row As C1.Win.C1FlexGrid.Row In myDataGrid.Rows
if row.Item("COLUMNNAME") = YOUR_VALUE then
' select range
C1.Win.C1FlexGrid.Select(row.Index, COLUMN_INDEX);
end if
Next
If you'd like to directly access a cell you may use Select method instead.

Can we hide VB.NET first selection column?

I hope I state my problem correctly. Kindly please look at the screenclip below :'
I prefer that the first column shown above is not displayed. Is there any design/programmatic way of achieving this?
Thank you!
Edited :
Using this link http://www.andreavb.com/forum/viewtopic_7951.html, I am able to remove the triangle from the selection column
This is using a DataGridView I assume? Just use the visible property for the row headers.
dgv.RowHeadersVisible = false;
Alternatively, you can set it to false using the Properties window.