Gridview combobox question

14 posts, 1 answers
  1. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 07 May 2009 Link to this post

    Hello,

    I'm trying to do the following.

    I've got a gridview that is triggered depending on which button you click (active and inactive button). So when active is clicked the gridview is loaded with all the active items and vice versa.

    Now in my gridview I've got one combobox column filled with 3 states (values: import, active, inactive). What I want to do is if the active items are loaded then in the combobox you can't select the active value and visa versa for inactive. the import values is always enabled.

    Next what I thought of doing is to have a combobox in my header of the grid. So if I select for example "import" in the header all items in the gridview will be set to be imported. A little like the checkbox in the header I guess.

    I looked for both things on the telerik forum and knowledge base but can't seem to find anything useful.

    Thanks in advanced.
    Gerbrand
  2. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 08 May 2009 Link to this post

    Hi Gerbrand,

    Please handle ValueChanging event to disable the selection of some desired value in the combo box editor. Take a look at the code below:

    void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e) 
        if (sender is GridComboBoxCellElement) 
        { 
            RadComboBoxEditor editor = this.radGridView1.ActiveEditor as RadComboBoxEditor; 
            if (editor != null && editor.SelectedValue.ToString() == "3"
            { 
                e.Cancel = true
            } 
        } 

    You could replace the default GridHeaderCellElement with a custom one that contains a RadComboBoxElement. Follow these steps:

    1. Handle CreateCell event.
    2. Inherit the custom cell form GridHeaderCellElement class.
    3. Override the CreateChildElements method to add the combo box.
    4. Override the ArrangeOveride method to arrange the combo.

    Please consider the following sample:

    void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e) 
        if (e.CellType == typeof(GridHeaderCellElement) && 
            e.Column.HeaderText == "Name"
        { 
            e.CellElement = new MyHeaderCell(e.Column, e.Row); 
        } 
     
    public class MyHeaderCell : GridHeaderCellElement 
        RadComboBoxElement comboBoxElement; 
     
        public MyHeaderCell(GridViewColumn column, GridRowElement row) 
            : base(column, row) 
        { 
        } 
     
        public override void UpdateInfo() 
        { 
            base.UpdateInfo(); 
            this.Text = ""
        } 
         
        protected override void CreateChildElements() 
        { 
            base.CreateChildElements();      
        
            comboBoxElement = new RadComboBoxElement(); 
             
            ((FillPrimitive)comboBoxElement.Children[0]).GradientStyle = GradientStyles.Solid; 
            ((FillPrimitive)comboBoxElement.Children[0]).BackColor = Color.White; 
            ((BorderPrimitive)comboBoxElement.Children[1]).GradientStyle = GradientStyles.Solid; 
            ((ComboBoxEditorLayoutPanel)comboBoxElement.Children[2]).Content.Alignment = ContentAlignment.MiddleCenter; 
            ((FillPrimitive)((ComboBoxEditorLayoutPanel)comboBoxElement.Children[2]).Content.Children[1]).GradientStyle = GradientStyles.Solid; 
            ((FillPrimitive)((ComboBoxEditorLayoutPanel)comboBoxElement.Children[2]).Content.Children[1]).BackColor = Color.White; 
     
            comboBoxElement.Items.Add(new RadComboBoxItem("Item 1")); 
            comboBoxElement.Items.Add(new RadComboBoxItem("Item 2")); 
            comboBoxElement.Items.Add(new RadComboBoxItem("Item 3")); 
     
            comboBoxElement.SelectedValueChanged += new EventHandler(comboBoxElement_SelectedValueChanged); 
            this.Children.Add(comboBoxElement); 
        } 
     
        void comboBoxElement_SelectedValueChanged(object sender, EventArgs e) 
        { 
            string text = comboBoxElement.SelectedText; 
            this.GridControl.GridElement.BeginUpdate(); 
            foreach (GridViewRowInfo row in this.GridControl.Rows) 
            { 
                row.Cells["Name"].Value = text; 
            } 
            this.GridControl.GridElement.EndUpdate(); 
        } 
     
        protected override void SetContentCore(object value) 
        {                 
        } 
     
        protected override SizeF ArrangeOverride(SizeF finalSize) 
        { 
            base.ArrangeOverride(finalSize); 
            if (comboBoxElement != null
            { 
                RectangleF clientRect = GetClientRectangle(finalSize); 
                RectangleF comboRect = new RectangleF(clientRect.X + 4, clientRect.Y, clientRect.Width - 8, clientRect.Height); 
                if (comboRect.Height > 20) 
                { 
                    comboRect.Y = (comboRect.Height - 20) / 2; 
                    comboRect.Height = 20; 
                } 
                comboBoxElement.Arrange(comboRect); 
            } 
            return finalSize; 
        } 

    In case you need further assistance, feel free to write us.

    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 08 May 2009 Link to this post

    Hi Jack,

    The valuechanging method is working.

    For the combobox header I did something similar but I got errors, so now I'm going to check your code example with the one I wrote. I'm sure it will work then..

    Thanks
  5. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 08 May 2009 Link to this post

    Okay just one small question regarding the comboboxheadercell

    my grid is loaded with an hierarchy (2 levels).

    my header combobox on the first level is triggered okay. all is changed to the one that is selected.
    Now if I click the + to view the childs I also get an comboboxheadercell. But the parents are changed, instead of the childs I just opened.

    is there a way to handle that? I think I have to change the SelectedValueChanged event in the class?

     
  6. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 08 May 2009 Link to this post

    Hi Jack

    Other issue. Now when I'm clearing my columns and rows I get a NullReference exception.

    radgrid.MasterGridViewTemplate.Columns.Clear();
    radgrid.MasterGridViewTemplate.Rows.Clear();

    Here is the stackTrace:


    at Telerik.WinControls.UI.TableViewDefinition.Measure(GridRowElement row, SizeF availableSize)
       at Telerik.WinControls.UI.GridTableElement.ArrangeOverride(SizeF finalSize)
       at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
       at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
       at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout()
       at Telerik.WinControls.RadElement.UpdateLayout()
       at Telerik.WinControls.ComponentLayoutElementTree.GetPreferredSize(Size sizeConstraints)
       at Telerik.WinControls.RadControl.GetPreferredSize(Size proposedSize)
       at System.Windows.Forms.Layout.DefaultLayout.LayoutAutoSizedControls(IArrangedElement container)
       at System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
       at System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
       at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
       at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
       at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
       at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement affectedElement, String affectedProperty)
       at System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String property)
       at System.Windows.Forms.Control.ControlCollection.Remove(Control value)
       at Telerik.WinControls.RadHostItem.PerformRoutedEventAction(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadHostItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.UI.RadTextBoxItem.OnTunnelEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.RaiseTunnelEvent(RadElement sender, RoutedEventArgs args)
       at Telerik.WinControls.RadElement.SetParent(RadElement parent)
       at Telerik.WinControls.RadElement.ChangeCollection(RadElement child, ItemsChangeOperation changeOperation)
       at Telerik.WinControls.RadElementCollection.OnClear()
       at System.Collections.CollectionBase.Clear()
       at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
       at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
       at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
       at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
       at Telerik.WinControls.UI.GridRowElement.DisposeChildren(RadElementCollection children)
       at Telerik.WinControls.UI.GridRowElement.Dispose(Boolean disposing)
       at Telerik.WinControls.UI.GridTableHeaderRowElement.Dispose(Boolean disposing)
       at Telerik.WinControls.RadComponentElement.Dispose()
       at Telerik.WinControls.RadElement.Cleanup()
       at Telerik.WinControls.UI.GridTableBodyElement.CleanupRows()
       at Telerik.WinControls.UI.GridTableElement.Update(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
       at Telerik.WinControls.UI.GridViewTemplate.UpdateUI(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
       at Telerik.WinControls.Data.DataAccessComponent.ResetGrid()
       at Telerik.WinControls.Data.DataAccessComponent.UpdateColumns(NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.UI.GridViewTemplate.UpdateColumns(NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.UI.GridViewColumnCollection.NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.Data.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       at Telerik.WinControls.Data.ObservableCollection`1.OnCollectionReset(IList oldItems)
       at Telerik.WinControls.Data.ObservableCollection`1.ClearItems()
       at Telerik.WinControls.Data.ItemObservableCollection`1.ClearItems()
       at Telerik.WinControls.UI.GridViewColumnCollection.ClearItems()
       Object reference not set to an instance of an object..
  7. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 08 May 2009 Link to this post

    Hi gerbrand,

    The Rows.Clear method is available only when the underlying data source supports this feature. The DataTable doesn't support this. Could you please confirm that this is the case. You could work around the issue by removing the rows manually. Check this sample:

    radgrid.GridElement.BeginUpdate(); 
    radgrid.MasterGridViewTemplate.Columns.Clear(); 
    while (radgrid.Rows.Count > 0) 
        radgrid.Rows.RemoveAt(0); 
    radgrid.GridElement.EndUpdate(); 

    If the issue persists try calling Begin/EndUpdate methods before and after clearing the rows.

    I am not sure that I understand your first question. Please give some more details and send your application.

     I will be glad to help you further and I am looking forward to your reply.

    Best wishes,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 11 May 2009 Link to this post

    Hi Jack,

    The null reference is solved.

    I'll try to explain my first question better, other wise I will make sample form to send to you.

    So I've got a gridview with an hierarchy
    parent -> child1
               -> child2
    parent -> child3
    parent -> child4
               -> child5
               -> child6

    Okay with the combobox headercell I've got this on the head of the gridview but also when you open a parent. I have a combobox headercell in my child gridview.

    Now when I change the value in the header cell of the parent grid all the parent rows a changed to that value. All good.
    Now when I open a parent and in the child gridview I change the header combobox all the parent rows are changed and not the child rows.

    I've looked how I could solve this but no luck at this moment.

    I hope this is better explained. If not let me know and I'll make an example.




  9. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 12 May 2009 Link to this post

    Hi gerbrand,

    Thank you for these details. Now I understand the issue.

    Look at the code inside the SelectedValueChanged event handler of MyHeaderCell. It iterates over the Rows collection of RadGridView. This collection contains all data rows from the first level when using a hierarchy. You could use the ViewInfo property of the header cell. This will return only the rows associated with the current child view. Here is the modified code:

    void comboBoxElement_SelectedValueChanged(object sender, EventArgs e) 
        string text = comboBoxElement.SelectedText; 
        this.GridControl.GridElement.BeginUpdate(); 
        foreach (GridViewRowInfo row in this.ViewInfo.Rows) 
        { 
            row.Cells["Name"].Value = text; 
        } 
        this.GridControl.GridElement.EndUpdate(); 

    I hope this helps. If you need further assistance, I will be glad to help.

    Best wishes,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 29 Dec 2009 Link to this post

    Hello,

    I've updated the telerik gridview to the version 2009.3.9.1103 and now my own comboboxheadercell isn't working any more. I tried several things, but nothing helped so I went back to the original state from when I just updated with the new version.

    I read this whole thread again to see if I did something wrong but the things Jack explained here is exact the same in my code. So I was wondering what I should change so the same functionality is handled like before. (described in this thread)

    Thanks
  11. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 30 Dec 2009 Link to this post

    Hi gerbrand,

    I tested the code from this thread with X.X.X.1103 and with our latest release Q3 2009 SP1 (2009.3.9.1203) and I was not able to find any issue. Please, send me your project and give more information on the issue. I will be glad to assist you further.

    Greetings,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 30 Dec 2009 Link to this post

    Hi Jack,

    I got everything working again except when my combobox is in my headercell of the gridview and I change it to another value, all the rows within the grid aren't changing.

    This is my comboboxheadercell class
    using System; 
    using System.Drawing; 
    using Telerik.WinControls; 
    using Telerik.WinControls.Primitives; 
    using Telerik.WinControls.UI; 
     
    namespace adlogix.userControls 
        public class ComboBoxHeaderCell : GridHeaderCellElement 
        { 
            private RadComboBoxElement combobox; 
             
            public ComboBoxHeaderCell(GridViewColumn column, GridRowElement row):base(column, row) 
            { 
                 
            } 
     
            public override void SetContent() 
            { 
                //base.SetContent(); 
            } 
     
            public override void UpdateInfo() 
            { 
                base.UpdateInfo(); 
                Text = ""
            } 
     
            //protected override void Dispose (bool disposing) 
            //{ 
            //    if(disposing) 
            //    { 
            //        combobox.ValueChanged -= combobox_ValueChanged; 
            //    } 
            //    base.Dispose(disposing); 
            //} 
     
            protected override void CreateChildElements() 
            { 
                base.CreateChildElements(); 
                combobox = new RadComboBoxElement(); 
     
                ((FillPrimitive)combobox.Children[0]).GradientStyle = GradientStyles.Solid; 
                ((FillPrimitive)combobox.Children[0]).BackColor = Color.White; 
                ((BorderPrimitive)combobox.Children[1]).GradientStyle = GradientStyles.Solid; 
                ((ComboBoxEditorLayoutPanel)combobox.Children[2]).Content.Alignment = ContentAlignment.MiddleCenter; 
                ((FillPrimitive)((ComboBoxEditorLayoutPanel)combobox.Children[2]).Content.Children[1]).GradientStyle = GradientStyles.Solid; 
                ((FillPrimitive)((ComboBoxEditorLayoutPanel)combobox.Children[2]).Content.Children[1]).BackColor = Color.White; 
     
                combobox.Items.Add(new RadComboBoxItem {Text = ""}); 
                combobox.Items.Add(new RadComboBoxItem { Text = Resources.GetString("Allow")}); 
                combobox.Items.Add(new RadComboBoxItem { Text = Resources.GetString("DisAllow")}); 
     
     
                combobox.SelectedValueChanged += ComboboxSelectedValueChanged; 
                Children.Add(combobox); 
                ApplyThemeToElement(combobox, "gerbrandsTheme"); 
            } 
     
            protected override void SetContentCore(object value) 
            { 
                base.SetContentCore(value); 
            } 
     
            protected override SizeF ArrangeOverride(SizeF finalSize) 
            { 
                base.ArrangeOverride(finalSize); 
                if (combobox != null
                { 
                    var clientRect = GetClientRectangle(finalSize); 
                    var comboRect = new RectangleF(clientRect.X + 4, clientRect.Y, clientRect.Width - 8, clientRect.Height); 
                    if (comboRect.Height > 20) 
                    { 
                        comboRect.Y = (comboRect.Height - 20) / 2; 
                        comboRect.Height = 20; 
                    } 
                    combobox.Arrange(comboRect); 
                } 
                return finalSize;  
            } 
     
            private void ComboboxSelectedValueChanged(object sender, EventArgs e) 
            { 
                var text = combobox.SelectedText; 
                GridControl.GridElement.BeginUpdate(); 
     
                var count = 0; 
                foreach (var row in ViewInfo.Rows) 
                { 
                    if (!row.IsSelected) continue
                    count++; 
                } 
     
                if (count > 1) 
                { 
                    foreach (var row in ViewInfo.Rows) 
                    { 
                        if (!row.IsSelected) continue
                         
                        row.Cells["Action"].Value = text; 
                    } 
                } 
                else 
                { 
                    foreach (var row in ViewInfo.Rows) 
                    { 
                        row.Cells["Action"].Value = text; 
                    } 
                } 
                GridControl.GridElement.EndUpdate();   
            } 
     
            private static void ApplyThemeToElement(RadElement item, string themeName) 
            { 
                if (item.ElementTree != null
                { 
                    var builder = ThemeResolutionService.GetStyleSheetBuilder((RadControl)item.ElementTree.Control, 
                                  item.GetThemeEffectiveType().FullName, string.Empty, themeName) as DefaultStyleBuilder; 
     
                    if (builder != null
                    { 
                        item.Style = new XmlStyleSheet(builder.Style).GetStyleSheet(); 
                    } 
                } 
            }  
        } 
     

    This is the code set on the gridview
    //  
    // myGrid 
    //  
    this.myGrid.Dock = System.Windows.Forms.DockStyle.Fill; 
    this.myGrid.GroupExpandAnimationType = Telerik.WinControls.UI.GridExpandAnimationType.Accordion; 
    this.myGrid.Location = new System.Drawing.Point(0, 57); 
    //  
    //  
    //  
    this.myGrid.MasterGridViewTemplate.AllowAddNewRow = false
    this.myGrid.MasterGridViewTemplate.AllowCellContextMenu = false
    this.myGrid.MasterGridViewTemplate.AllowColumnChooser = false
    this.myGrid.MasterGridViewTemplate.AllowColumnHeaderContextMenu = false
    this.myGrid.MasterGridViewTemplate.AllowColumnReorder = false
    this.myGrid.MasterGridViewTemplate.AllowDeleteRow = false
    this.myGrid.MasterGridViewTemplate.AllowDragToGroup = false
    this.myGrid.MasterGridViewTemplate.AutoGenerateColumns = false
    this.myGrid.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; 
    this.myGrid.MasterGridViewTemplate.EnableGrouping = false
    this.myGrid.MasterGridViewTemplate.ShowFilteringRow = false
    this.myGrid.Name = "myGrid"
    this.myGrid.ShowGroupPanel = false
    this.myGrid.ShowItemToolTips = false
    this.myGrid.Size = new System.Drawing.Size(1011, 316); 
    this.myGrid.TabIndex = 1; 
    this.myGrid.ThemeName = "gerbrandsTheme"
    this.myGrid.UseScrollbarsInHierarchy = true
    this.myGrid.ViewCellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.myGrid_ViewCellFormatting); 
    this.myGrid.CreateCell += new Telerik.WinControls.UI.GridViewCreateCellEventHandler(this.myGrid_CreateCell); 
    this.myGrid.ValueChanging += new Telerik.WinControls.UI.ValueChangingEventHandler(this.myGrid_ValueChanging); 
    this.myGrid.ValueChanged += new System.EventHandler(this.myGrid_ValueChanged); 

    these are the events set on the gridview
    private void myGrid_ValueChanging(object sender, ValueChangingEventArgs e) 
       if (!(sender is GridComboBoxCellElement)) return
     
       var editor = rgvAllItems.ActiveEditor as RadComboBoxEditor; 
       if (editor != null && editor.Value.ToString() == "Action"
       { 
           e.Cancel = true
       } 
             
    private void myGrid_CreateCell(object sender, GridViewCreateCellEventArgs e) 
       if (e.CellType == typeof(GridHeaderCellElement) && e.Column.HeaderText == "Action"
       { 
           e.CellElement = new ComboBoxHeaderCell(e.Column, e.Row); 
       } 
     
    private void myGrid_ValueChanged(object sender, EventArgs e) 
       var cell = sender as GridDataCellElement; 
       if (cell == nullreturn
     
       if (((GridViewDataColumn)cell.ColumnInfo).FieldName != "Action"
       { 
                      
       } 
             
    private void myGrid_ViewCellFormatting(object sender, CellFormattingEventArgs e) 
       if (!(e.CellElement is GridDetailViewCellElement)) return
       var cell = e.CellElement as GridDetailViewCellElement; 
       if (cell == nullreturn
       cell.ChildTableElement.DrawBorder = false
       cell.ChildTableElement.TableBodyElement.DrawBorder = false
       cell.RowInfo.Height = 150; 


    this is how I load the columns and set the datasource for the mastergridviewtemplate and the childtemplate:
    private void LoadItemsHierarchyColumns() 
       myGrid.MasterGridViewTemplate.Columns.Add(new GridViewImageColumn { FieldName = "Status", HeaderText = "Status", ReadOnly = true, DataType = typeof(Image), ImageLayout = ImageLayout.None }); 
       myGrid.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "SiteId", HeaderText = "Site Id", HeaderTextAlignment = ContentAlignment.MiddleCenter, ReadOnly = true}); 
       myGrid.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "SiteName", HeaderText = "Site Name", HeaderTextAlignment = ContentAlignment.MiddleCenter, ReadOnly = true }); 
       myGrid.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "Childs", HeaderText = "Total Childs", HeaderTextAlignment = ContentAlignment.MiddleCenter, ReadOnly = true }); 
                 
       var c = new GridViewComboBoxColumn("Action"
               { 
                   DataSource = new[] { "", Resources.GetString("Allow"), Resources.GetString("DisAllow") }, 
                   FieldName = "Action"
                   HeaderText = "Action"
                   UniqueName = "ActionColumn"
                   ReadOnly = false 
                }; 
       myGrid.MasterGridViewTemplate.Columns.Add(c); 
       myGrid.MasterGridViewTemplate.AutoGenerateColumns = false
       myGrid.MasterGridViewTemplate.DataSource = DtAdserverParents; //is a datatable
                 
       var template = new GridViewTemplate { AllowAddNewRow = false, AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill}; 
       template.Columns.Add(new GridViewImageColumn { FieldName = "Status", HeaderText = "Status", ReadOnly = true, DataType = typeof(Image), ImageLayout = ImageLayout.None }); 
       template.Columns.Add(new GridViewTextBoxColumn { FieldName = "SiteId", HeaderText = "Site Id", HeaderTextAlignment = ContentAlignment.MiddleCenter, IsVisible = false,ReadOnly = true }); 
       template.Columns.Add(new GridViewTextBoxColumn { FieldName = "ZoneId", HeaderText = "Zone Id", HeaderTextAlignment = ContentAlignment.MiddleCenter, ReadOnly = true }); 
       template.Columns.Add(new GridViewTextBoxColumn { FieldName = "ZoneName", HeaderText = "Zone Name", HeaderTextAlignment = ContentAlignment.MiddleCenter, ReadOnly = true }); 
     
       var b = new GridViewComboBoxColumn("Action"
               { 
                   DataSource = new[] { "", Resources.GetString("Allow"), Resources.GetString("DisAllow") }, 
                   FieldName = "Action"
                   HeaderText = "Action"
                   UniqueName = "ActionColumn"
                   ReadOnly = false 
               }; 
                 
       template.Columns.Add(b); 
       template.AutoGenerateColumns = false
       template.DataSource = DtAdserverChilds; //is a datatable
     
       //add rows template 
       myGrid.MasterGridViewTemplate.ChildGridViewTemplates.Add(template); 
     
       //create relation between both 
       var relation = new GridViewRelation(myGrid.MasterGridViewTemplate) 
                      { 
                          ChildTemplate = template, 
                          RelationName = "SiteZones" 
                      }; 
       relation.ParentColumnNames.Add("SiteId"); 
       relation.ChildColumnNames.Add("SiteId"); 
       myGrid.Relations.Add(relation); 
     
       myGrid.Dock = DockStyle.Fill; 

    Maybe I forgot something, but I can't seem to find what.
    Thanks in advanced
  13. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 30 Dec 2009 Link to this post

    Hi gerbrand,

    I looked at your code and I found the issue. There is an issue with the combobox column and the SelectedValueChanged event is not fired. I will research this further. You can work around the issue by handling SelectedIndexChanged event instead. In addition you are referencing the column Action. However, you are setting the UniqueName for this column to ActionColumn. The Cells collection uses the UniqueName property of the column for its identification. I modified the code of your ComboboxSelectedValueChanged event in this way:

    private void ComboboxSelectedValueChanged(object sender, EventArgs e)
    {
        var text = combobox.SelectedText;
        GridControl.GridElement.BeginUpdate();
     
        var count = 0;
        foreach (var row in ViewInfo.Rows)
        {
            if (!row.IsSelected) continue;
            count++;
        }
     
        if (count > 1)
        {
            foreach (var row in ViewInfo.Rows)
            {
                if (!row.IsSelected) continue;
     
                row.Cells["ActionColumn"].Value = text;
            }
        }
        else
        {
            foreach (var row in ViewInfo.Rows)
            {
                row.Cells["ActionColumn"].Value = text;
            }
        }
        GridControl.GridElement.EndUpdate();
    }

    I hope this helps.

    Regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  14. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 31 Dec 2009 Link to this post

    Hi Jack,

    Thanks a lot, it's working again now.
    Is there a reason why the selectedvaluechanged event isn't triggered anymore?
    I also noticed you can't override the dispose method of the GridHeaderCellElement, this was used to remove the event from the combobox. Maybe this isn't needed any more in the new version?

    Thanks a lot
  15. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 04 Jan 2010 Link to this post

    Hi gerbrand,

    This is an issue that we introduced with our latest version. Currently we are working on it and it will be addressed in one of our upcoming releases. The Dispose method is replaced with the DisposeManagedResources one. This is because we changed the life-cycle of our elements. Find more about this in the following blog article

    Regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for WinForms is Visual Studio 2017 Ready