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

Get value(s) from cell to textbox

5 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Byterat Prabhata
Top achievements
Rank 1
Byterat Prabhata asked on 04 May 2010, 12:02 PM
Private Sub rgv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rgv.Click

        '
        ' Retrieve data to variable
        '
        dsId = rgv.CurrentRow.Cells("idRoute").Value.ToString
        dsDepart = rgv.CurrentRow.Cells("city1").Value.ToString
        dsArrival = rgv.CurrentRow.Cells("city2").Value.ToString
        'dsStatus = rgv.CurrentRow.Cells("status").Value.ToString

        '
        ' Set TextBox
        '
        tKode.Text = Format(Val(dsId), "00000")
        cbCity1.Text = dsDepart
        cbCity2.Text = dsArrival

    End Sub

Codes above works well on WindowsForms. My question is how to achieve same scenario with WPF?
I just want get some value(s) from grid to textbox based on column name as string.
Thanks.

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 04 May 2010, 12:13 PM
Hi,

You can use CurrentItem property. Just cast it to your object type and get desired property value.

Greetings,
Vlad
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.
0
Byterat Prabhata
Top achievements
Rank 1
answered on 04 May 2010, 01:00 PM
        tKode.Value = rgv.CurrentItem.ToString ' tKode.Value is : System.Data.DataRow

        tKode.Value = rgv.SelectedItems(0).ToString ' tKode.Value is empty

        rgv.SelectedItem = (DirectCast(Me.rgv.ItemsSource, String).ToString)
        tKode.Value = rgv.SelectedItem.ToString ' does not work

        tKode.Value = rgv.CurrentCell.ToString 'tKode.Value is empty

Is there sample code?
0
Byterat Prabhata
Top achievements
Rank 1
answered on 07 May 2010, 02:37 PM
Let me simplify the question.

I do this code in Windows Form Application and run smoothly as needed:

Dim varCity As String = rgv.CurrentRow.Cells(varTableFieldName).Value.ToString

Now, i need do same thing in WPF Application. But, how??

Dim varCity As String = ???

Code please. I'm frustrated and stuck here.
0
Maya
Telerik team
answered on 11 May 2010, 09:13 AM
Hi Byterat Prabhata,

You may achieve the desired result in the following way:

Dim currentRow = TryCast(Me.myGrid.CurrentItem, dataRow)
Dim city = currentRow("varTableFieldName")

The second possibility (but not a preferred one) is to use the elements of the UI as:

Dim row = TryCast(Me.myGrid.ItemsContainerGenerator.ContainerFromItem(Me.myGrid.CurrentItem), GridViewRow)
Dim cellValue = row.Cell[4].Value.ToString();

Cell[4] specifies the cell whose content you want to work with. 



Kind regards,
Maya
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.
0
Byterat Prabhata
Top achievements
Rank 1
answered on 12 May 2010, 08:53 AM
Thanks for respond. But i still don't get it.
Recently i use WindowsFormsHost to hold Windows Form Application's form. So i can get busy with another part.

Here sample application what i need. Hope help.

Sample Apps
Tags
GridView
Asked by
Byterat Prabhata
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Byterat Prabhata
Top achievements
Rank 1
Maya
Telerik team
Share this question
or