Selected ListView item column value - vb.net

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.

Related

Get the actual value of a BoundField element in a gridview VB.NET

The following image depicts the full gridview I have:
I'm able to get the values of the second column (project_ID) in the back end as follows:
Dim val As String = grdProjects.SelectedRow.Cells(1).Text.ToString
For instance if I press the Select of the third row I'll get back the value 3.
My problem appears when the gridview is updated and has less records as the one in the following image.
If I press the second record I get the value 2 instead of the value 4 that I'd like to get.
Any suggestions please on how to get the actual value of the cell instead of the number of the selected row?
I might be wrong but in VB.net datagrids SelectedRow does not exist, SelectedRows do exist.
Anyway, try this way and let me know if it work:
On the RowEnter or CellClick event use the E.RowIndex to get what you want. Do as follow:
Private Sub DataGrid1_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGrid1.RowEnter
Dim CellValue As String = DataGrid1.Rows(e.RowIndex).Cells("Project_ID").Value.ToString
End Sub
Notice that for the .cells() I use the name of the column, this is better because if in the future you add columns this code will not need to be changed. Easier code maintenance always pay! Also. Cell().Value instead Cell().Text
Nandostyle

Filtering data read from a SQL table based upon user input in a TextBox

I have a table on a SQL Server that will be accessed by different users. Each user will be able add and delete rows in the table on the server.
Currently, the form displays the entire contents of the table and all of the rows are editable. I am trying to allow users to input words or letters into a TextBox at the top of the form to filter the rows which are displayed on the form.
1) I have an event like this:
Public Event ValuesChanged(sender As Object, e As EventArgs)
And a method like this:
Private Sub SearchTxtBox_TextChanged(sender As Object, e As EventArgs)_
Handles SearchTxtBox.TextChanged
2) I need to filter based on the user-input from the Textbox.Text.
I would like the filter to be based on each letter entered into the text box. So, for instance, when you type the letter "A", it would redraw and filter to only show rows that have an "A" or "a". When you type "Ape", it would do the same by narrowing it further.
Ok I think I've got it figured out:
Dim dataview As DataView = _ds.ProgramOwners.DefaultViewdataview.RowFilter = String.Format("Program like '%{0}%'", SearchTxtBox.Text)
This filters based on the Program Row and the user input :)

Binding combobox selected value to a specific column of current row (not a datagridview)

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. :)

Is there a way to allow only unique values in a column of an Infragistics UltraWinGrid?

I'm using an Infragistics UltraWinGrid with a column of drop-down boxes. I don't want the user to be able to select the same value for multiple rows in that column. Is there a simple (or heck, I'd settle for advanced) way to do this?
I'm using VB.NET
-EDIT-
I tried setting a filter on the data source for the drop-down box. But when I did that, the values in the other boxes in that column started disappearing (not the values themselves, but the descriptions that they were supposed to represent, so instead of reading "Information", it just said "1"). All of the cells in a column refer to the same combo box, so if you filter out a value from the data source for one of them, you filter it out for all of them.
I'm currently trying to catch a CellChange event and check against all other currently-used values. If it was already used, I would put up a message saying as much and revert back to the old value. However, the value comes back as the previously-saved one, so... not helpful. About to see if I can use the "text" property.
Since you're using Infragistics, you could use an UltraDropDown which is bound to a DataTable (or something similiar) which you can add a "Selected" column in addition to a column holding the values you want to show.
As each value is selected (via AfterCellUpdate or AfterCellListCloseUp for instance), you could update the "Selected" column in that data source and use a column filter to only show items which haven't been marked as selected. That way as items are selected or removed, the contents of the drop-down would be automatically updated.
To clear the selected flag from the old value, you can use the BeforeCellUpdate event to access the cell's current value then perform a lookup on the data source bound to the UltraDropDown using that value to clear the flag.
Solved it:
The trick was to use BeforeCellUpdate whose BeforeCellUpdateEventArgs has a "NewValue" and a "Cancel" member. I just look through all of the items in the column to see if any of them match the new value. If one does, I notify the user and cancel the operation.
And that's it. Here's the code:
Private Sub myUltraWinGrid_BeforeCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles myUltraWinGrid.BeforeCellUpdate
If e.Cell.Column.Key = "myColumn" Then
Dim newValue As Integer = CInt(e.NewValue)
For Each row As Infragistics.Win.UltraWinGrid.UltraGridRow In myUltraWinGrid.Rows
If row.Cells("myColumn") IsNot e.Cell _ 'So I'm not checking against the current cell
AndAlso CInt(row.Cells("myColumn").Value) = newValue Then
MsgBox("That value has already been used in this column")
e.Cancel = True
End If
Next
End If
End Sub

getting value from other column besides the valuemember column in Infragistics ultracombo

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