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

GridViewLookUpColumn Custom Objects

4 Answers 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul Gallen
Top achievements
Rank 1
Paul Gallen asked on 16 Dec 2008, 05:38 PM
HI

I have custom objects of type phone and each phone has a phonetype example Phone.PhoneType.Name="Business"

I have a grid which is bound to a generic list of Phone. One of the columns in the grid is a GridViewLookupColumn named  phonetype (ie. Business, Mobile, Fax etc..)
On the init of my app I assign the PhoneTypes to the data source

Me

 

.PhoneTypeBindingSource.DataSource = CMXApplication.LookUps.PhoneTypes

 

 

CType(Me.PhonesRadGridView.Columns("PhoneType"), Telerik.WinControls.UI.GridViewLookUpColumn).DataSource = Me.PhoneTypeBindingSource.DataSource

Because of the nature of the custom objects I intercept the Cellformatting event, to display the name of the phone type

 

 

Private Sub PhonesRadGridView_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles PhonesRadGridView.CellFormatting

 

 

If e.CellElement.RowIndex >= 0 Then

 

 

 

 

 

If e.CellElement.ColumnIndex = 1 Then

 

 

 

 

e.CellElement.Text =

CType(PhonesBindingSource(e.CellElement.RowIndex), FTS.CMX.CMXModel.Phone).PhoneType.Name

 

 

End If

 

 

 

 

 

End If

 

 

 

 

 

End Sub

so far so good. When I edit the grid row I select a different phonetype in my GridViewLookUpColumn (PhoneType). I need to assign  a phonetype from the  GridViewLookUpColumn  to my phone. What I think I need to do is this, capture the CellEndEdit value from the GridViewLookUpColumn and assign a phonetype to my phone.

When I query the GridViewLookUpColumn  it is not the selected value from my grid

Can you give me pointers on how to achieve the desired results?

 

 

Private Sub PhonesRadGridView_CellEndEdit(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles PhonesRadGridView.CellEndEdit

 

 

Dim Phone As FTS.CMX.CMXModel.Phone = ContactProxy.Contact.Phones(PhonesRadGridView.CurrentRow.ViewInfo.CurrentIndex)

 

 

If PhonesRadGridView.CurrentRow.Cells(0).Value = String.Empty Then

 

 

 

 

 

 

If Phone.EntityState = EntityState.Added Then

 

 

 

 

 

PhonesRadGridView.Rows.RemoveAt(ContactProxy.Contact.Phones.Count - 1)

ContactProxy.Contact.Phones.Remove(Phone)

 

End If

 

 

 

 

 

 

Else

 

 

 

 

 

 

If e.ColumnIndex = 1 Then 'assign the phone type to the phone

 

 

 

 

 

 

'CType(Me.PhonesRadGridView.CurrentCell, Telerik.WinControls.UI.GridComboBoxCellElement).Text

 

Debug.WriteLine(

CType(Me.PhonesRadGridView.CurrentCell, Telerik.WinControls.UI.GridComboBoxCellElement).Value)

 

 

 

End If

 

 

 

 

 

 

End If

 

 

 

 

 

 

End Sub

 

 

 

 

Thanks P

4 Answers, 1 is accepted

Sort by
0
Paul Gallen
Top achievements
Rank 1
answered on 17 Dec 2008, 05:04 PM
Hi Guys


Any movement on this


Thanks

P
0
Nick
Telerik team
answered on 18 Dec 2008, 04:50 PM
Hi Paul Gallen,

Thank you for contacting us.

Please see the sample code below:

Dim t As New DataTable() 
t.Columns.Add("some column"GetType(String)) 
t.Columns.Add("phone column"GetType(String)) 
t.Rows.Add("some text""Mobile"
t.Rows.Add("some text""Business"
t.Rows.Add("some text""Business"
t.Rows.Add("some text""Fax"
Me.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = False 
radGridView1.Columns.Add(New GridViewTextBoxColumn("some column")) 
Dim c As New GridViewLookUpColumn("phone column"
c.DataSource = New String() {"Mobile""Business""Fax"
c.FieldName = "phone column" 
radGridView1.Columns.Add(c) 
Me.radGridView1.DataSource = t 
Me.radGridView1.MasterGridViewTemplate.EnableFiltering = True 

This example will soon become available in our documentation. When you edit the values in the comboboxes they are saved in your database (the t DataSet in the case above).

Do not hesitate to write me back if you have more questions.
 

Best wishes,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Paul Gallen
Top achievements
Rank 1
answered on 18 Dec 2008, 05:26 PM
Hi Nick,

Thanks for getting back to me, I have another thread running where I am having trouble with grids generally. I think it is because the grid is bound to custom objects in a generic list . I am investingating at the moment and I will get back to you with my findings

Best

P
0
Nick
Telerik team
answered on 19 Dec 2008, 03:43 PM
Hi Paul Gallen,

Thank you. Please make sure that you access the RadGridView only from the thread where it was created.

Greetings,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Paul Gallen
Top achievements
Rank 1
Answers by
Paul Gallen
Top achievements
Rank 1
Nick
Telerik team
Share this question
or