Hello,
I've got a bit of a problem with Q2 2009 GridView. I use a child GridViewTemplate, but whenever I try to expand its row (with row.IsExpanded = true) I get a NullReferenceException at Telerik.WinControls.UI.DataGroup.get_RowCount()
at Telerik.WinControls.UI.GridViewInfo.SetViewInfoToRows(DataGroup rootGroup)
at Telerik.WinControls.UI.GridViewInfo.InitializeChildViewInfo()
at Telerik.WinControls.UI.GridViewTemplate.CreateGridViewInfo(DataGroup rootGroup, GridViewDataRowInfo parentRow)
at Telerik.WinControls.UI.GridViewDataRowInfo.SetExpanded(Boolean value)
at Telerik.WinControls.UI.GridViewRowInfo.set_IsExpanded(Boolean value).
After looking closely at what's going on I noticed that DataGroup.owner is null, and DataGroup.IsDisposed == true. I think the group gets disposed in DataAccessComponent.InitDataGrid() when I set DataMember of my ChildGridViewTemplate to null and its DataSource to a DataTable that was earlier filled with data.
After that the DataGroups never get recreated, so when I try to expand my ChildGridViewTemplate, DataGroups are still disposed (with owner set to null) and I get the exception. I also noticed that if I add new data rows to the DataTable after assigning it as DataSource than the new rows expand just fine, only the old ones throw exceptions.
So my question is, is there any way I can force the DataGrid to recreate disposed DataGroup for already existing rows ?
Regards,
Piotr Kochanowski
Please, can you help me with this question:
I have a grid with combobox column. All of these comboboxes have different DataSorce property (assigned thouth intercepting CellEditorInitialized event):
| Private Sub gridSort_CellEditorInitialized(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles gridSort.CellEditorInitialized |
| Dim i As Integer |
| If gridSort.CurrentColumn.HeaderText = "Order" Then |
| Dim editor As Telerik.WinControls.UI.RadComboBoxEditor = gridSort.ActiveEditor |
| Dim editorElement As Telerik.WinControls.UI.RadComboBoxEditorElement = editor.EditorElement |
| If gridSort.Rows.IndexOf(gridSort.CurrentRow) = 1 Then |
| i = editorElement.SelectedIndex |
| editorElement.DataSource = New String() {"Minimized", "Maximized"} |
| editorElement.SelectedIndex = i |
| If i < 0 Then |
| Dim ii As Integer = 0 |
| For Each ss As String In editorElement.DataSource |
| If ss = gridSort.CurrentRow.Cells.Item(1).Value Then |
| editorElement.SelectedIndex = ii |
| Exit For |
| End If |
| ii += 1 |
| Next |
| End If |
| Else |
| i = editorElement.SelectedIndex |
| editorElement.DataSource = New String() {"Ascending", "Descending"} |
| editorElement.SelectedIndex = i |
| End If |
| End If |
| End Sub |
1. Every time editorElement.SelectedIndex have value -1 (and I must set value by searching throuh DataSource list and comparing with cell Value). For values Minimized/Maximized it's done and work fine, but for values Ascending/Descending it's not and when I click on combobox field - it's filled by empty sring.
Comparing with Value of cell is not fine because here can be some duplicated values (sic!) and I can not determine what value was in this cell before. Is here some method of determine SelectedIndex after changing of value?
2. I want to collect data choosen by user. But ComboBox cell in grid have not SelectedIndex (or I can not find it?) and I must to obtain it from Value property. Problem is similiar with previous question - how can I find a real position of value in DataSource list?
| Imports Telerik.WinControls |
| Imports Telerik.WinControls.UI |
| Imports System.Text |
| Imports System.Data.Common |
| Imports System.ComponentModel |
| Public Class Form1 |
| Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| Dim Item As GridMenuItem = New GridMenuItem |
| Dim Grid As RadGridView = Item.Grid |
| Grid.Columns.Add(New GridViewDataColumn("A")) |
| Grid.Columns.Add(New GridViewDataColumn("b")) |
| Grid.Columns.Add(New GridViewDataColumn("c")) |
| Grid.Rows.Add("Hello", "World", "!") |
| Grid.Rows.Add("Hello", "World", "!") |
| Grid.Rows.Add("Hello", "World", "!") |
| Grid.ReadOnly = False |
| Grid.Columns(0).Width = 5 |
| Grid.Columns(1).ReadOnly = True |
| Grid.Columns(2).IsVisible = False |
| RadDropDownButton1.Items.Clear() |
| RadDropDownButton1.Items.Add(Item) |
| End Sub |
| End Class |
Here's the item:
| Imports Telerik.WinControls.UI |
| Imports Telerik.WinControls |
| Imports System.ComponentModel |
| Public Class GridMenuItem |
| Inherits RadMenuItemBase |
| Implements INotifyPropertyChanged |
| Dim _Grid As RadGridView |
| Dim _HostItem As RadHostItem |
| Public ReadOnly Property Grid() As RadGridView |
| Get |
| Return Me._Grid |
| End Get |
| End Property |
| Protected Overrides Sub CreateChildElements() |
| _Grid = New RadGridView() |
| _Grid.BeginInit() |
| _Grid.BindingContext = New BindingContext() |
| _Grid.MultiSelect = True |
| _Grid.AutoSize = False |
| _Grid.HideColumnChooser() |
| _Grid.ReadOnly = False |
| _Grid.ShowGroupPanel = False |
| _Grid.ShowNoDataText = False |
| Dim Template As GridViewTemplate = _Grid.MasterGridViewTemplate |
| Template.AllowCellContextMenu = False |
| Template.AllowColumnChooser = False |
| Template.AllowColumnHeaderContextMenu = False |
| Template.AllowColumnReorder = False |
| Template.AllowAddNewRow = False |
| Template.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill |
| Template.EnableGrouping = False |
| Template.ShowFilteringRow = False |
| Template.ShowRowHeaderColumn = False |
| Template.ShowColumnHeaders = False |
| _Grid.EndInit() |
| _HostItem = New RadHostItem(_Grid) |
| Me.Children.Add(_HostItem) |
| End Sub |
| Protected Overrides Function MeasureOverride(ByVal availableSize As System.Drawing.SizeF) As System.Drawing.SizeF |
| Dim size As System.Drawing.SizeF = MyBase.MeasureOverride(availableSize) |
| Return _Grid.Size |
| End Function |
| End Class |