Some question on GrideView

5 posts, 0 answers
  1. Ray Wang
    Ray Wang avatar
    14 posts
    Member since:
    Oct 2009

    Posted 30 Nov 2009 Link to this post

    Hello Telerik

    We have two questions in Grideview

    1:Can we add two different control in one cell of Grideview?
       we want to add a progress bar and corresponding text in one cell,please see attached
    If Grideview can't do that, do you know if tehre is any other control can realize this?

    2: Our GridView :when we want to add a item in sub-table, and datasource has been update(we can find the new item in datasource), but this new item didn't show in sub-table

    BTW, How to change the color of current selected row (Default is orange, we want to change to Gray)

  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 01 Dec 2009 Link to this post

    Hi Ray Wang,

    To create several controls in a grid cell, you should do the following steps:

    1. Create a custom cell derived from GridDataCellElement
       1.1 First, create a class that inherits from GridDataCellElement
       
    public class   CustomProgressCell : GridDataCellElement
            public CustomInfoCell(GridViewColumn column, GridRowElement row) 
                : base(column, row) 
            {             
            
    }

       1.2 Add the elements that you want to show in the cell as members of CustomProgressCell class
         
    private StackLayoutPanel panel;
    private RadLabelElement label;
    private RadProgressBarElement progressBar;

      1.3 To add the elements in the cell you should override CreateChildElements method.
      
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
     
        this.panel = new StackLayoutPanel();
        this.panel.Margin = new System.Windows.Forms.Padding(5);
        this.panel.Orientation = System.Windows.Forms.Orientation.Vertical;
     
        this.label = new RadLabelElement();
        this.label.TextAlignment = ContentAlignment.MiddleCenter;
        this.panel.Children.Add(this.label);
     
        this.progressBar = new RadProgressBarElement();
        this.progressBar.MinSize = new Size(0, 20);
        this.panel.Children.Add(this.progressBar);
     
        this.Children.Add(this.panel);
    }
      
    1.4 Also you should override SetContentCore method to support initialization of the cell value with the value of its elements.
      
    protected override void SetContentCore(object value)
    {
        object cellValue = value;
     
        if (cellValue is DBNull || cellValue == null)
            cellValue = 0;
     
        this.progressBar.Value1 = (int)cellValue;
        this.label.Text = "Value: " + cellValue.ToString();
    }

      2. We finished our work on the custom cell element, but now we should associate the cells of the Progress Column with this custom cell type. In order to do so, handle the CreateCell event which is called once for each cell when RadGridView is shown for the first time. When this event is fired for the cells of ProgressColumn, we set the CellType property of the GridViewCreateCellEventArgs to our custom cell type:

    private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridDataCellElement))
        {
            GridViewDataColumn dataColumn = e.Column as GridViewDataColumn;
             
            if (dataColumn.UniqueName == "Progress")
            {
                e.CellType = typeof(CustomProgressCell);
            }
        }
    }

    3. In addition to make the look of the cell outstanding we should do the following lines in the constructor of the form:

    this.radGridView1.Columns["Progress"].ReadOnly = true;
    this.radGridView1.Columns["Progress"].MinWidth = 70;
    this.radGridView1.GridElement.RowHeight = 50;

    Presently we can not reproduce your issue with sub-tables. Could you provide us with example project?

    If you have further questions, feel free to ask us.

    Greetings,
    Svett
    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ray Wang
    Ray Wang avatar
    14 posts
    Member since:
    Oct 2009

    Posted 01 Dec 2009 Link to this post

    Hello Telerik

    Thank you very much. You always give us big help.

    As to the second problem I stated :

    2: Our GridView :when we want to add a item in sub-table, and datasource has been update(we can find the new item in datasource), but this new item didn't show in sub-table

    May be I didn't described it clearly. This problem is not related to the first one. It is another problem. We didn't use the customer cell type here. We only use the orignal cell type. we apply each row as a folder, and sub-table show the contents of folder. We want to realize "right-click" to add a sub-folder in each row. we have already realized this using update the datasource.  (We have binded generic list). Bur our problem is the update data didn't show in sub-table imediately. but when we go to other page and load return the grideview. we can see the update data(new adding sun-folder). It seems that when we update the datasource, grideview didn't refresh the show screen.




  5. Ray Wang
    Ray Wang avatar
    14 posts
    Member since:
    Oct 2009

    Posted 02 Dec 2009 Link to this post

    Below is the code we used

    List<DirectorySource> entries = this.radGridView.MasterGridViewTemplate.ChildGridViewTemplates[0].DataSource as List<DirectorySource>;
                    FileSystemInfo fileInfo = new DirectoryInfo(strSaveFilePath);
                    DirectorySource newRowData = new DirectorySource(fileInfo);
                    //the date added :newRowData
                    newRowData.DateModified = "DateModified";
                   
     this.radGridView.MasterGridViewTemplate.ChildGridViewTemplates[0].DataSource = entries;
                    this.radGridView.MasterGridViewTemplate.ChildGridViewTemplates[0].Update(GridUINotifyAction.Reset);
  6. Svett
    Admin
    Svett avatar
    728 posts

    Posted 03 Dec 2009 Link to this post

    Hello Ray Wang,

    Presently, this is an issue in RadGridView. It will be addressed in the next version of RadControls for Winforms (Q1 2010). Your Telerik points have been updated. If you have further questions, feel free to contact us.

    All the best,
    Svett
    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