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

[Solved] Item Index of new record

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip Senechal
Top achievements
Rank 1
Philip Senechal asked on 08 Apr 2008, 06:26 PM
I have a fairly normal grid that I'm running with an OnItemCreated sub. The sub does some really basic things like assign shared calendars to the date pickers and add a "Select an Item" to the combo boxes.

The other thing I have it do is to check one of the fields in each record for a particular value. If that value is not in the table that feeds a combo, it adds it manually to the combo. This works great when editing existing records because I already have an Index for the grid item, however, when adding a new record, my routine errors because the Index hasn't been created yet. I need the Index to perform a query and check for a value.

So what I really need is a way to determine whether or not the index exists when someone clicks on Add a Record. If it doesn't exist, I will just bypass my routine.

Can you help me figure out a way to determine if the item index exists?

This is the line of code that errors:

Dim task_id As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("task_id").ToString()


Thanks.

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 11 Apr 2008, 12:18 PM
Hi Philip Senechal,

On ItemCreated you can check if you are inserting or editng an item. And depending on that - pass or implement your routine. Try with the following code snippet for instance:

Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)  
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then 
        If e.Item.OwnerTableView.IsItemInserted Then 
              'passyour routine   
        Else 
              'your routine here  
        End If 
    End If 
End Sub 


All the best,
Iana
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Philip Senechal
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or