Results 1 to 20 of 20

Thread: datagrid column color

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    datagrid column color

    I need help to change color of a selected unbound column in datagrid.

    Please!!!

  2. #2
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    Look here these is guide line to do what you want

    http://www.syncfusion.com/FAQ/Window...44c.aspx#q900q
    Using VS 2010 on Fw4.0

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    still do not get it.

    My column is unbound checkbox style, like this:

    VB Code:
    1. Dim col As DataColumn = New DataColumn
    2.   col .DataType = System.Type.GetType("System.Boolean")
    3.   col .AllowDBNull = False
    4.   col .ReadOnly = False
    5.   col .Caption = "col 1"
    6.   coll .ColumnName = "col 1"
    7.                
    8.   ds.Tables(0).Columns.Add(col )

  4. #4
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    If I understand well, you have a DataSet in witch you create manually a Boolean Column. Then I guest you bound the DataSet to the datagrid, is that right ?

    Well the usual technique to change color for DataGrid Column is by overriding the Paint event from the DataGridTextBoxColumn or DataGridBoolColumn.
    Using VS 2010 on Fw4.0

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    yes, I do have a dataset to bound with the grid. but the boolean column is not from the dataset, it is something else I append to that grid.

  6. #6
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    I think I miss something...

    The code that you show me above, add a column to your DataSet, right ? So is this column is the one that you wish to add some color?
    Using VS 2010 on Fw4.0

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    My first 2 columns are from a dataset, then I use the above code to append one more column.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    all I want to do is to make some visual changes, like highlight that column, change border of that column or something on column header, etc, to let the user know that he is selecting this datagrid column.

  9. #9
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    Quote Originally Posted by Palmtree
    My first 2 columns are from a dataset, then I use the above code to append one more column.

    OK, So you have a DateSet with three Column. Boudned to a DataGrid and you want to add some color to one or more of those column. Is that right ?

    If so then, add a DataGridTableStyle to your DataGrid with 3 DataGridColumnStyle to it, and you will have to Overrides the paint event from the Column that you wish to add some color.

    You may refer to the point 5.14 and/or 5.32 for this page
    http://www.syncfusion.com/FAQ/Window...44c.aspx#q787q
    Using VS 2010 on Fw4.0

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    I have a DateSet with three Column. The first 2 are boudned, and the last one is not. I want to add some color to the last unbounded column.

  11. #11
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    Quote Originally Posted by Palmtree
    I have a DateSet with three Column. The first 2 are boudned, and the last one is not. I want to add some color to the last unbounded column.

    Ok i thing there is something that you misunderstand here ..
    The Code that you show me add a column to the DataSet, and if you bound this DataSet to the DataGrid then all the 3 columns will be considered "Bounded" to the Grid!

    So you may handle the layout by using DataGridTableStyle and DataGridColumnStyle.
    Using VS 2010 on Fw4.0

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    Oh, Great! Thanks for pulling me to the correct direction.

    But I still do not see how to change the color of either that column or its column headtext or its border.

  13. #13
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    Quote Originally Posted by Palmtree
    Oh, Great! Thanks for pulling me to the correct direction.

    But I still do not see how to change the color of either that column or its column headtext or its border.
    Good! now that we talk of the same thing it will be easier

    First you have to know that Each DataGrid have a TableStyles collection property that can hold several Table Layout, and for each TableStyles there is a GridColumnStyles collection property that can hold all Column layout style.

    The basic DataGridColomnStyle are realy "basic" they don't have many formating methode/functon. So you will have to create your own DataGridColumnStyle for a CheckBox column type it could be something like

    VB Code:
    1. Public Class MyDataGridBoolColumn
    2.      Inherits DataGridBoolColumn
    3.      ' Do stuff
    4. End Class

    Now instend of appening a Standart DataGridBoolColumn to the GridColumnStylesCollection of the TablesStyle from the DataGrid, append a new instance of MyDataGridBoolColumn

    For example in the Load Event of a Form.

    VB Code:
    1. Private Sub frmCamionPlanif_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.     Dim ColStyle As MyDataGridBoolColumn = New MyDataGridBoolColumn
    3.  
    4.     Me.dtgSiloDisponible.TableStyles(0).GridColumnStyles.Add(ColStyle)
    5. End Sub

    For other detail look at the first link i've post there is many info about this or at the "George Shepherd's Windows Form FAQ" form my signature
    Using VS 2010 on Fw4.0

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    Thanks again.

    I have long and hard way to go, bcz the Inheritance is totally new to me.

  15. #15
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    Quote Originally Posted by Palmtree
    Thanks again.

    I have long and hard way to go, bcz the Inheritance is totally new to me.
    Once you'll undertand Inheritance a huge will be open be you
    Using VS 2010 on Fw4.0

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    I bet. Maybe that is why VB.net is hot nowadays.

    If this column thing won't take you too much time, would you give me some code for me to study?

  17. #17
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    Here a little article about Inheritance it might help !!
    Using VS 2010 on Fw4.0

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    Yes,I think i have read this before. BUT still can not actually USE IT in my code.

  19. #19
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: datagrid column color

    Quote Originally Posted by Palmtree
    I bet. Maybe that is why VB.net is hot nowadays.

    If this column thing won't take you too much time, would you give me some code for me to study?
    Here is a example of custom DatatGrid Column. DataGridTimePickerColumn
    Using VS 2010 on Fw4.0

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    471

    Re: datagrid column color

    Thanks so much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width