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

How do I access a grid on a DocumentWindow?

1 Answer 107 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Declan
Top achievements
Rank 2
Declan asked on 23 Jul 2009, 01:56 PM
My main form loads a RadDock and a toolWindow containing a PanelBar and RadList.

On clicking items in the RadList a new DocumentWindow is opened. This window is a class which inherits from DocumentWindow.

This loads the document window
LogDocument documentLog = new LogDocument(); 
documentLog.Text = documentTitle; 
documentLog.CurrentFileId = selectedIndex; 
 
documentLog.Load();  // Loads data into grid 
 
AirFile.AddNewMostRecentFile(documentTitle, selectedIndex); 
 
this.radDock.AddDocument(documentLog); 

My inherited class (only some of it for brevity)
    class LogDocument : DocumentWindow 
    { 
        public LogDocument() 
        { 
             AddGridToForm(); 
        } 
 
        public void Load() 
        { 
             LoadGridWithData(); 
        } 
 
 
        private void AddGridToForm() 
        { 
            RadTabStrip radTabStrip = new Telerik.WinControls.UI.RadTabStrip(); 
            TabItem tabGridItem = new Telerik.WinControls.UI.TabItem(); 
            TabItem tabDetailItem = new Telerik.WinControls.UI.TabItem(); 
 
            //  
            // radTabStrip1 
            //  
            radTabStrip.AutoScrollMargin = new System.Drawing.Size(0, 0); 
            radTabStrip.AutoScrollMinSize = new System.Drawing.Size(0, 0); 
            radTabStrip.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(191)))), ((int)(((byte)(219)))), ((int)(((byte)(254))))); 
            radTabStrip.Dock = DockStyle.Fill; 
            radTabStrip.Location = new System.Drawing.Point(0, 0); 
            radTabStrip.Name = "radTabStrip"
            radTabStrip.ScrollOffsetStep = 5; 
            radTabStrip.TabScrollButtonsPosition = Telerik.WinControls.UI.TabScrollButtonsPosition.RightBottom; 
            radTabStrip.Text = "radTabStrip"
            //  
            // tabGridItem 
            //  
            tabGridItem.Alignment = System.Drawing.ContentAlignment.BottomLeft; 
            //  
            // tabItem1.ContentPanel 
            //  
            tabGridItem.ContentPanel.BackColor = System.Drawing.Color.Transparent; 
            tabGridItem.ContentPanel.CausesValidation = true
            tabGridItem.IsSelected = true
            tabGridItem.Margin = new System.Windows.Forms.Padding(4, 0, 0, 0); 
            tabGridItem.Name = "tabGridItem"
            tabGridItem.StretchHorizontally = false
            tabGridItem.Text = "Grid"
            //  
            // tabItem2 
            //  
            tabDetailItem.Alignment = System.Drawing.ContentAlignment.BottomLeft; 
            //  
            // tabItem2.ContentPanel 
            //  
            tabDetailItem.ContentPanel.BackColor = System.Drawing.Color.Transparent; 
            tabDetailItem.ContentPanel.CausesValidation = true
            tabDetailItem.Margin = new System.Windows.Forms.Padding(4, 0, 0, 0); 
            tabDetailItem.Name = "tabDetailItem"
            tabDetailItem.StretchHorizontally = false
            tabDetailItem.Text = "Item Detail"
             
            // TODO 
            // Add controls to show current row details in a form 
 
 
 
            grid.Dock = DockStyle.Fill; 
            grid.RowsChanged += new Telerik.WinControls.UI.GridViewCollectionChangedEventHandler(GridRowsChanged); 
            grid.DoubleClick += new System.EventHandler(GridDoubleClick); 
            // 
            // Add TabItems to TabStrip 
            // 
            radTabStrip.Items.AddRange(new Telerik.WinControls.RadItem[] { tabGridItem, tabDetailItem }); 
            // 
            // Add grid to tab 1 
            // 
            tabGridItem.ContentPanel.Controls.Add(grid); 
            // 
            // Add tab strip to form 
            // 
            Controls.Add(radTabStrip); 
        } 
 
 
        /// <summary> 
        /// Persist changes to current row to database. 
        /// </summary> 
        /// <param name="sender"></param> 
        /// <param name="e"></param> 
        private void GridRowsChanged(object sender, GridViewCollectionChangedEventArgs e) 
        { 
            Save(); 
        } 
 
 
 




In the constructor I add controls to the document including a RadGrid. When many documents are opened I have a UI similar to VisualStudio.

My Main form has a menu containing a delete button. When this button is clicked I want to delete the current grid row on the current active window.

My difficulty is that I cannot figure out how to reference the "delete item" code in the class LogWindow:
        public void DeleteRow() 
        { 
            // Delete code here 
 
            // then save changes to db 
            Save(); 
 
        } 


Any help would be appreciated.



1 Answer, 1 is accepted

Sort by
0
Boryana
Telerik team
answered on 27 Jul 2009, 10:14 AM
Hello Declan,

Thank you for contacting us.

I managed to construct a sample project from the snippets in your post. In the implementation of DeleteRow() you can use the Remove() method to delete the current row. Please, note that before deleting it you have to check whether it exists and its RowInfo is GridViewDataRowInfo.

Since, you have declared your DeleteRow() method as public, you should not encounter any issues, accessing it when handling the RadButton click. I have attached the sample project that demonstrates the described behavior.

I hope this is helpful. If you have further questions, do not hesitate to write me back.

Best wishes,
Boryana
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
Tags
Dock
Asked by
Declan
Top achievements
Rank 2
Answers by
Boryana
Telerik team
Share this question
or