Results 1 to 8 of 8

Thread: DataGridView Cell with MultiLine and Colors

  1. #1

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    DataGridView Cell with MultiLine and Colors

    Hello

    Need some help to know if there's anyway to do what i'm trying to do...

    I have a big datagridview that has a list of items, that have several states, every state has a date. My dgv will look like this:
    ----- Date1 | Date2 | Date3 ...
    It1 |
    It2 |
    It3 |

    The same item can have multiple states in the same date, for example:
    The item1 enters the factory in the date1, and leaves the factory in the same date1, what i need it's that the intersection cell, have one line with the background in green with an F (means that the item enters in the factory), and in the same cell, but in another line (multiline) in the same cell i need another F but this time with the background red (means that item leaves the factory).

    The usuals columns doesn't allow me to do this, i created a simple code to use a image column and then draw a image that does what i want, but i don't like the final results and it's a little slow, and when i select the full row, i don't have the usual selected cell visual effect in this columns...
    I was thinking to create a datagridview column with a different type (inherited) but i don't know what column to use as base column for my column, image column and then paint the content of another control in the cell or another type?

    If anyone have or know some way of doing this please tell me?

    Thanks

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: DataGridView Cell with MultiLine and Colors

    Here is something that might assist. It's not what you want but in a different order, food for thought.

    The concept is that if the first column of the custom DataGridView does smart repeating values which means if the values were

    1 A
    1 B
    1 V
    2 D
    2 C

    You see

    Code:
    1 A
      B
      V
    2 D
      C
    I uploaded the project w/o the XML data so there are in two zip files, simply place the XML in the debug folder and alter the path for reading the data in the form.

    Hope this helps in some way
    Attached Files Attached Files
    Last edited by kareninstructor; Jul 9th, 2011 at 10:13 PM.

  3. #3

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: DataGridView Cell with MultiLine and Colors

    Thanks for the reply and the code... It may be useful in the future (other projects), but for me in this case i can't apply it, first the structure of the database doesn't allow me to do that, and then it will duplicate some much rows that visually it will be very confusing for the user...

    I'm thinking for now, create some kind of method to resize and write text according to the number of the lines and the available space in the cell, or just create some image with a default size and adjust the image to the cell...

    BTW, do you know some kind of grid or custom dgv that can be manipulated like the dynamic tables in excel?

    Thanks

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: DataGridView Cell with MultiLine and Colors

    Quote Originally Posted by mickey_pt View Post
    BTW, do you know some kind of grid or custom dgv that can be manipulated like the dynamic tables in excel?
    Thanks
    Not that I have seen in non-commercial grids for .NET

  5. #5

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: DataGridView Cell with MultiLine and Colors

    I'll leave this thread open for now, to see if anyone have another idea...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  6. #6
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: DataGridView Cell with MultiLine and Colors

    do you mean you wish to change the background colour of cells in a column based on what value it (or something else on the same row) contains?
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  7. #7

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: DataGridView Cell with MultiLine and Colors

    I want to have multiple colors in the same cell, for example:
    Line1 (color red) - state done
    Line2 (color red) - state done
    Line3 (color green) - state current working
    Line4 (no color) - state next job

    For testing purposes i defined the columns has image columns, but now i have a big problem...

    The dgv layout it's like the attached image, and after filling the data of the first columns until the black separator, i add the date columns manually (the interval it's defined in the options) and they are image columns, for each row in the table i need to see when it arrives to each state and when it ends that state, but by the way that i'm doing this, it's a very slow proccess...

    After filling the data:
    vb.net Code:
    1. For Each row As DataGridViewRow In DataGridView1.Rows
    2.             checkStates(row)
    3.         Next

    CheckStates:
    vb.net Code:
    1. Dim dr() As DataRow = dtPF.Select(String.Format("idPF={0}", row.Cells("idPF").Value))
    2.  
    3.         If CBool(dr(0)("State1")) = True Then
    4.             row.Cells(CDate(dr(0)("DateState1")).ToString("dd.MMM")).Value = IMGGP() 'Return the correct image
    5.  
    6.             If CBool(dr(0)("State2")) = True Then
    7.                 row.Cells(CDate(dr(0)("DateState2")).ToString("dd.MMM")).Value = IMGF() 'Return the correct image
    8.             End If
    9.         End If
    10.     End Sub

    Some info to speed up this process?
    THanks
    Attached Images Attached Images  

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  8. #8

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: DataGridView Cell with MultiLine and Colors

    I found out why the process it's very slow...

    If i filter the datatable it takes arround 13 seconds to run 300 rows, if i query the database directly and use the row directly it takes less then 1 second...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

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