I'm currently using VB .NET as the language for the program. What are the steps to read the contents of cells of a selected row as well as the values of controls that may be used within a cell?
Thanks
5 Answers, 1 is accepted
Generally, the DataContext of the button defined in a column would be its corresponding item. So, you may use it for finding the values you want.
Indeed, the recommended approach is to have a business object with exposed properties used for the source of the grid. Thus the values will be kept even when scrolling. Otherwise, if not properties to bind to are available, you will loose the data as the virtualization is turned on by default.
How exactly do you populate the RadGridView ?
Maya
the Telerik team
Oh the grid is bound to a RIA object for the majority of the columns in the grid. Only the command button and Numeric UpDown control are not bound to anything. The idea is to extract data from the selected row to pass to another RIA object to populate a shopping cart. While waiting on a response, I did discover a way to extract the data I needed to pass this to the other RIA process. Here's is what I'm doing to get the information from the bound columns:
Dim senderElement As FrameworkElement = TryCast(e.OriginalSource, FrameworkElement) Dim row As GridViewRow = senderElement.ParentOfType(Of GridViewRow)() If row IsNot Nothing Then If row.Cells.Count > 0 Then Dim _ItemKey As String = row.Cells(kColItemKey).Content.Text Dim _ItemID As String = row.Cells(kColItemID).Content.Text Dim _ItemDesc As String = row.Cells(kColItemDesc).Content.Text Dim _ItemPrice As String = row.Cells(kColListPrice).Content.Text Dim tester As String tester = String.Format("Item Key; {0}" & vbCrLf & "Item ID: {1}" & vbCrLf & "Item Desc: {2}" & vbCrLf & "Item Price: {3}", _ItemKey, _ItemID, _ItemDesc, _ItemPrice) MessageBox.Show(tester, "Row Info", MessageBoxButton.OK) End If End IfThe kCol constants are the actual column numbers within the grid. This seems to work like a champ no matter what row I select on the grid, so part of my problem is solved. The final piece of the problem is getting the value of the RadNumericUpDown control I have placed in a column to allow a user to select a specific quantity. Using the technique above, the value in the content is nothing, which makes sense as it isn't actually the column cell holding the information put the control placed within the cell. So is there a way to read the value of a control set up within a cell template?
Thanks
Ok I figured out the last part of the problem. Drilling into the row object in debug I discovered if I simply did this:
Dim _QtySelected As String = row.Cells(kColQty).Content.ValueI was able to retrieve the value of the RadNumericUpDown control.. So unless you see any issues with what I'm doing, I guess I'll go this route for now. Thanks for the help.
I am glad that you found your solution. Generally, as mentioned previously, it is usually recommended to bind the element to particular property from the business object so that you may retrieve them easily, ensure they will not be lost on scrolling and that the correct value is taken. However, as you say that you do not require to bind the element to a property, you may get its value following the approach you choose.
Maya
the Telerik team