Adding different columns programatically

13 posts, 0 answers
  1. Gonzalo
    Gonzalo avatar
    76 posts
    Member since:
    Oct 2012

    Posted 13 Feb 2012 Link to this post

    Me.RadGridView1.Rows.Clear()
    Me.RadGridView1.ColumnCount = 5
     
    RadGridView1.Columns(0).HeaderText = "Id."
    RadGridView1.Columns(1).HeaderText = "Name"
    RadGridView1.Columns(2).HeaderText = "Under Appeal"
    RadGridView1.Columns(3).HeaderText = "Terminated"
    RadGridView1.Columns(4).HeaderText = "#"
     
    RadGridView1.Columns(1).Width = 100
     
     
    RadGridView1.Rows.Add ( 1, "John", True, True )
    RadGridView1.Rows.Add ( 2, "Mary", True, False )
    RadGridView1.Rows.Add ( 3, "Peter", False, True )


    How do I get the radgridview to display checkboxes for boolean values for the last two columns? The columns get manually loaded.

    Best regards
  2. David
    David  avatar
    67 posts
    Member since:
    Aug 2010

    Posted 14 Feb 2012 Link to this post

    Where in you code do you add the Columns?

    Do you do this in the designer?

    If it is then when you add a Column to the Gird there should be a drop down to select what column type you would like

    if you are adding them in code you would need to use the correct Column Class 

    http://www.telerik.com/help/winforms/gridview-columns-gridviewcheckboxcolumn.html 


  3. Gonzalo
    Gonzalo avatar
    76 posts
    Member since:
    Oct 2012

    Posted 14 Feb 2012 Link to this post

    Thanks David for your answer. In the code below where would you set the checkbox controls to handle the columns with boolean values ? programatically speaking. Best regards, G

    Me.RadGridView1.Rows.Clear()
    Me.RadGridView1.ColumnCount = 5
      
    RadGridView1.Columns(0).HeaderText = "Id."
    RadGridView1.Columns(1).HeaderText = "Name"
    RadGridView1.Columns(2).HeaderText = "Under Appeal"
    RadGridView1.Columns(3).HeaderText = "Terminated"
    RadGridView1.Columns(4).HeaderText = "#"
      
    RadGridView1.Columns(1).Width = 100
      
      
    RadGridView1.Rows.Add ( 1, "John", True, True )
    RadGridView1.Rows.Add ( 2, "Mary", True, False )
    RadGridView1.Rows.Add ( 3, "Peter", False, True )
  4. David
    David  avatar
    67 posts
    Member since:
    Aug 2010

    Posted 14 Feb 2012 Link to this post

    Ah just had a look, The line in you code "Me.RadGridView1.ColumnCount = 5" This is what is adding the column rather then using this you can do the following,  I'm not sure if there is a way to convert a column once it has been created.
    Me.RadGridView1.Rows.Clear()
      
    Dim ID As New GridViewDecimalColumn()
    ID.Name = "ID"
    ID.HeaderText = "Id"
    RadGridView1.MasterTemplate.Columns.Add(ID)
     
    Dim Name As New GridViewTextBoxColumn()
    Name.Name = "Name"
    Name.HeaderText = "Name"
    Name.Width = 100
    RadGridView1.MasterTemplate.Columns.Add(Name)
     
    Dim Under_Appeal as New GridViewCheckBoxColumn()
    Under_Appeal.DataType = GetType(Boolean)
    Under_Appeal.Name = "Under_Appeal"
    Under_Appeal.HeaderText = "Under Appeal"
    RadGridView1.MasterTemplate.Columns.Add(Under_Appeal)
     
    Dim Terminated as New GridViewCheckBoxColumn()
    Terminated.DataType = GetType(Boolean)
    Terminated.Name = "Terminated"
    Terminated.HeaderText = "Terminated"
    RadGridView1.MasterTemplate.Columns.Add(Terminated)
       
    Dim Hash As New GridViewDecimalColumn()
    Hash.Name = "Hash"
    Hash.HeaderText = "#"
    RadGridView1.MasterTemplate.Columns.Add(Hash)
      
    RadGridView1.Rows.Add ( 1, "John", True, True )
      
    RadGridView1.Rows.Add ( 2, "Mary", True, False )
      
    RadGridView1.Rows.Add ( 3, "Peter", False, True )
  5. Gonzalo
    Gonzalo avatar
    76 posts
    Member since:
    Oct 2012

    Posted 14 Feb 2012 Link to this post

    Thanks David ;-). Just what the doctor ordered :)
  6. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 16 Feb 2012 Link to this post

    Hi Gonzalo,

    Thank you for writing.

    As David mentioned, the code that you have provided does not show how you are adding the columns to your grid. If your column is added as GridViewCheckBoxColumn, you cannot change it afterwards. You need to either add the correct column initially or remove the undesired columns and add GridViewCheckBoxColumn instead.

    I hope this helps. 

    Greetings,
    Stefan
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Gonzalo
    Gonzalo avatar
    76 posts
    Member since:
    Oct 2012

    Posted 16 Feb 2012 Link to this post

    Stefan,

    Thanks for your kind reply. As I stated in my previous message David's message help me clarify the issue and I am happy moving to a different topic ... RadCharts :) . Your message is appreciated and acknowledged. Thanks for all your support. I am not usually developing win forms apps but I had this request so I never say "no" :-).

    Best regards,

    G

    PS. By the way, I am already exploring Q1 2012 :-) Cheers.
  8. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 21 Feb 2012 Link to this post

    Hi Gonzalo,

    Thank you for the nice words. I am glad that everything is OK.

    Enjoy the new bits of Q1 2012 and let us know if you have any questions there.
     
    Regards,
    Stefan
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  9. Gonzalo
    Gonzalo avatar
    76 posts
    Member since:
    Oct 2012

    Posted 23 Feb 2012 Link to this post

    Continuing with this great topic based on the previous example how would you add child row programmatically. Assuming...

    RadGridView1.Rows.Add ( 1, "John", True, True )
    RadGridView1.Rows.Add ( 2, "Mary", True, False )
    RadGridView1.Rows.Add ( 3, "Peter", False, True )
     
    something like ...
     
    RadGridView1.ChildRows.Add ( 1, "sugar", 2.00 )
    RadGridView1.ChildRows.Add ( 1, "cake", 12.00 )
    RadGridView1.ChildRows.Add ( 1, "butter", 3.00)
    RadGridView1.ChildRows.Add ( 2, "cake", 12.00)
    Thank you so much.

    G
  10. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 24 Feb 2012 Link to this post

    Hi Gonzalo,

    Thank you for your question.

    In general, I would suggest to separate the different subjects into different threads, so they will be easier to find when looking for them.

    In regards to your inquiry, first I would suggest that you get acquainted with our documentation concerning the different methods for Populating RadGridView with data and Binding to Hierarchical RadGridView. Both of these help sections will help you understand how RadGridView works, thus will help you choose the best approach for populating with data for your application.

    Attached you can find a sample project demonstrating how to create a child template for your RadGridView, relate it with the MasterTemplate and add some row in it. I hope that you find this information helpful.
     
    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  11. Gonzalo
    Gonzalo avatar
    76 posts
    Member since:
    Oct 2012

    Posted 24 Feb 2012 Link to this post

    Thanks Stefan and my apologies for not having created a different thread, I will follow your advise from now on ;-) I will look into your response and get back to you as needed. Thanks again for all your patience. G
  12. Gonzalo
    Gonzalo avatar
    76 posts
    Member since:
    Oct 2012

    Posted 24 Feb 2012 Link to this post

    Thanks Stefan for the example you rocked ;-).

    G
  13. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 29 Feb 2012 Link to this post

    I am glad I could help. Do not hesitate to open a new thread when you have any other questions.

    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top