This is a migrated thread and some comments may be shown as answers.

SelectedIndexChanged

1 Answer 169 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JustinWong
Top achievements
Rank 1
JustinWong asked on 11 Apr 2010, 08:03 AM
Hi:

I have a GridView with 2 columns (uniquenames = col1 and col2)
col1 is a ComboBoxColumn with 2 dropdown items.
col2 is a textboxColumn.

What I want to accomplish is this:
Whenever a user selects the first item from the combobox (col1), I want one set of text (e.g.: "You have selected the first item for row n") to show up on col2 for that row.  Similarly, when user selects the second item from the combobox, I want another set of text to show up in col2 (e.g.: "You have slsected the second item for row n").

How to accomplish this? I have not a clue. Have searched the site for 2 hours. Saw a couple of threads that are somewhat close to what I want, but couldn't modify the codes presented on those threads to do what I want. 

Your help is really appreciated. Thanks so much!

Justin

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 14 Apr 2010, 02:36 PM
Hello JustinWong,

You can achieve this behavior by subscribing to the ValueChanged event handler. You can use the following code snippet:
 
Private isUpdateing As Boolean = False
 
Private Sub radGridView_ValueChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim dataRow As GridViewDataRowInfo = TryCast(Me.radGridView.CurrentRow, GridViewDataRowInfo)
 
    If isUpdateing OrElse dataRow Is Nothing Then
        Return
    End If
 
    Dim cbEditor As RadComboBoxEditor = TryCast(Me.radGridView.ActiveEditor, RadComboBoxEditor)
 
    If cbEditor IsNot Nothing Then
        Dim editorElement As RadComboBoxEditorElement = TryCast(cbEditor.EditorElement, RadComboBoxEditorElement)
 
        Dim rowIndex As Integer = Me.radGridView.MasterGridViewTemplate.Rows.IndexOf(dataRow)
 
        Dim message As String = String.Format("You have slsected {0} item for row {1}", editorElement.SelectedIndex, rowIndex)
 
        isUpdateing = True
        dataRow.Cells("TextColumn").Value = message
        isUpdateing = False
 
        Me.radGridView.MasterGridViewTemplate.Update(GridUINotifyAction.StateChanged)
    End If
End Sub


Note that the new row does not exist in the rows collection of the grid because it contains only data rows. The sample code above works for data rows only.

If you need further assistance do not hesitate to write us back.
 

Kind regards,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
JustinWong
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or