I am fairly new to using infragistics controls (started yesterday). While they are (very) impressive they do add another layer of complexity, which I am muddeling through. So I am asking what I feel to be a fairly simple issue:
I am trying to get the value from another column besides the one that is displayed in the combobox. So far all my attempts have only grabbed the value of the header column not the value in the row column that was selected.
Specifically I want to take from my ultracombobox the value from the lastname column when a row is selected and place it in a textbox.
The below code I have so far retruns the header column (LastName) and nothing else no matter which row I select.
Private Sub ucboPatientInfo_RowSelected(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.RowSelectedEventArgs) Handles ucboPatientInfo.RowSelected
ucboPatientInfo.ValueMember = "accounts"
LastName = ucboPatientInfo.SelectedRow.Band.Columns(1).ToString
I added the: "ucboPatientInfo.ValueMember = 'accounts'" to help clarify what my code is doing it is not actually in this part of the code.
Please help
Looks like you found a working solution to your own problem. I thought I would just add in some more information and things to consider.
You may want to avoid a hard index refrence to your cell, in case the position changes in the future as you add new data to the grid's datasource. Say you insert another column ahead of lastName, now your .Cells(5) will return incorrect data.
Instead try using the Cells("columnName") for access like this:
LastName = ucboPatientInfo.Cells("LastName").Value
You should also try to use the eventArgs and sender objects within your event and avoid a direct control refrence. So your code could look like this instead:
LastName = e.Row.Cells("LastName").Value.ToString()
Glad to see your workin things out in any case.
found correct combination:
LastName = ucboPatientInfo.Cells(5).Value
Related
I have created a listview,
and id like to be able to change the selected item values. I wonder if is possible to somehow access the "ID" string of the selected item.
I created an event to detect when the user selects an item and tried colID.Index.ToString but it just returns the actual column index. Anyone able to provide a syntax that will return the selected item ID?
Private Sub lvwCars_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvwCars.SelectedIndexChanged
currentCarIDString = colID.Index.ToString
end sub
It's either going to be the item text or subitem text.
currentCarIDString = lvwCars.Items(colID.Index).Text
or
currentCarIDString = lvwCars.Items(colID.Index).SubItems(1).Text
I found something that works for my specific case
ListView.FocusedItem.Index
since my ID is always going by up by one, this solution works perfect. However if anyone can offer a solution that can retrieve the actual value of a row of a column, that would be great.
I have set a combobox to be visible in column1 of my Datagridview. Now I'm trying to fill same row of Datagridview where Combobox appears, from Combobox_Key_Down event. This is my code for showing combobox:
Private Sub My_DGV_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles MY_DGV.CellMouseClick
If e.RowIndex >= 0 Then
With My_DGV
If .Columns(.Rows(e.RowIndex).Cells(e.ColumnIndex).ColumnIndex).Name = "Column1" Then
.CurrentCell = .Rows(.CurrentRow.Index).Cells(.CurrentCell.ColumnIndex)
Show_Combobox(.CurrentRow.Index, .CurrentCell.ColumnIndex) 'function that shows my Combobox in that cells
Combo.Visible = True
Else
Combo.Visible = False
End If
End With
End If
End Sub
I tried many things, but I don't know how to determine in which row Combobox appears and how give that Datagridview row my Combobox values. Someone please give me a clue of what should I do. Thanks in advance !
The first problem with your approach is that the DGV can have only one DataSource: it can either show the m:m association table or the related elements. If you include columns from one of the tables into the query for display, the table becomes non updatable and users can be confused why they cannot edit something they can see. It seems of little value they way you describe it, since they cannot see the detail data until after they make a selection.
Next, it requires another datatable to supply the details for CboColB. Since you want the DGV bound to a DataTable easy updates, you end up having to poke data into cells over and over.
Finally, consider what the user is confronted with. Using a Country table (200+ countries/locales with ISO code and name) and a list of flag colors, a table for CountryFlagColors will have hundreds and hundreds of rows (at just 2 colors per flag).
A better display might be to filter the m:m table (flagcolor) to a selected item so the user is only confronted with the data subset they are currently interested in:
The datatable used in the DGV is built from the m:m table:
The Country column is hidden.
When they choose from the CBO at the top, that is used as a RowFilter to limit the rows to the relevant ones.
In the RowValidating event, when the country cell is DBNull, copy the SelectedValue from the country combo to the DGV cell to fill in the blank
I would probably really make the user click a button and manually add a row so I could seed the country value then rather than depend on events.
It uses a DataAdapter and after adding X number of flag definitions, da.Update(dtFlagColors) applies/saves all the changes.
Ok, so that provides the core functionality to assign N color selections to define the flag colors for a country. The missing element is the 'details' for the Color item.
I added a meaningless int and string item to the Color table, one way to display these would be to create an alias in the SQL with the important details. Displaying them as discrete elements can either make the query non updatable or invites the user to edit things they cannot edit here. My silly SQL:
"SELECT Id, Name, Concat(Name , ' (' , intItem , ' ' , stritem,')') As Info from FColor"
Then use 'Info' as the display member on the CBO column in the dgv:
dc = DirectCast(dgvCF.Columns(0), DataGridViewComboBoxColumn)
dc.DataSource = dtFlagColors
dc.DisplayMember = "info"
dc.ValueMember = "id"
dgvCF.DataSource = dtSample
The combo column has its own datasource of course, in order to display one thing and use another for as the Value to give back to you. Result (the values are silly):
It is not exactly what you want, but comes close and is much simpler. It also requires almost no code for driving the associative entity. Another alternative would be to use a DGV as the second picker so you can show the extended data and manually add rows to a DGV:
If you set the dropdown style to Nothing, it looks like a text column.
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.
I have a DataGridView that is bound to a BindingSource that is bound to a DataSet. For most of the columns, the default sort order is fine, but for one of the columns, the displayed data isn't good for sorting and I have a hidden calculated column, SortCol in the DataSet to make a better sort for that column.
The problem is, SortCompare, where I have code to redirect the sort to SortCol doesn't get called. I've been Googling this for a couple hours, and it seems like everyone says that SortCompare isn't used when the DataSource property is set on the DataGridView - it expects the bound DataSource to perform the sort - and then the topic is dropped, without any advice on how you can actually perform the sort.
I've looked in the BindingSource and the DataSet, and I'm not seeing any exposed interfaces for doing custom sorting. I'm all set to derive my own BindingSource to do it, but I'm hoping there's a way that's less of a headache to do what should be a lot more straightforward.
EDIT: As there appears to be some confusion, I want to clarify that I am not asking how to perform an initial set on the DataSet or even on the DataGridView. That is trivial. I am specifically asking how I can link clicking on one column header to sorting based on another column (or more generally by other criteria).
I am now working on seeing if I can get it working with Programmatically set as the SortMode, as the easy way appears to not exist.
UPDATE: No dice - using one Sort overload puts the SortGlyph on the hidden column, the other gives an error: DataGridView control is data-bound. The control cannot use the comparer to perform the sort operation.
UPDATE: Unless you set the SortGlyph after sorting by the other column. I guess that's the solution I'm going to have to go with; though I think I will leave this open in case someone else comes up with a better answer for future reference.
The solution I finally used for this was to set the SortMode to Programmatic and handle the 'ColumnHeaderMouseClick' event as follows:
Private Sub DG_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DG.ColumnHeaderMouseClick
If DG.Columns(e.ColumnIndex) Is NonSortColumn Then
Select Case NonSortColumn.HeaderCell.SortGlyphDirection
Case SortOrder.Ascending
DG.Sort(SortColumn, System.ComponentModel.ListSortDirection.Descending)
NonSortColumn.HeaderCell.SortGlyphDirection = SortOrder.Descending
Case Else
DG.Sort(SortColumn, System.ComponentModel.ListSortDirection.Ascending)
NonSortColumn.HeaderCell.SortGlyphDirection = SortOrder.Ascending
End Select
End If
End Sub
It still feels like a bit of a kludge compared to just handling the SortCompare event or an equivalent from the BindingSource or DataSet, but at least it seems to be working.
I have a database that I am using in a VB 2010 project. What I did was removed a textbox for a database field that I dragged onto the form and replaced it with a combobox. The field name was orderstatus.
The problem is this: since I removed the textbox field from the form, I can't seem to bind the combobox value to the field in the active record. In other words, orderstatus textbox doesn't exist anymore. I want to let the user pick a status from the combobox and store that value to orderstatus so that it's saved to the current record my database.
I want to do something like this:
Private Sub Button16_Click_1(sender As System.Object, e As System.EventArgs) Handles Button16.Click
orderstatus = ComboBox13.SelectedValue
Me.OrdersDataSet.orders(0).orderstatus = orderstatus
Me.Validate()
Me.OrdersBindingSource.EndEdit()
Me.TableAdapterManager12.UpdateAll(Me.OrdersDataSet)
End Sub
but it doesn't like my second line where I try to assign the value to the field, saying there is no row 0. All I want to do is put the selected value of the combobox into the orderstatus field of the record being created (or updated).
I've also tried using:
Me.OrdersDataSet.orders.orderstatusColumn = orderstatus
and I get a message saying that the property of the column is ReadOnly. I'm not sure how that's possible because I configured the dataset to update, etc.
I should probably mention that I'm not using a datagridview but a details view, if that makes a difference. I've seen some talk about how to do this using datagridview and don't know if that would work in my case.
What am I doing wrong? What should I use to update just the column I want in the current row?
Ugh, turns out I had forgot to set the databinding properties of the field in question to save directly to the binding source and also select the selecteditem to bind. It was right there and I didn't realize. Ya live and learn. :)