Format the DataGrid

Source: Internet
Author: User

Public class datagridcoloredtextboxcolumn
Inherits datagridtextboxcolumn 'inheritance Interface
Public rowcollection as new collection 'is used to store the set of row numbers.
Public backcolor () as color 'is used to store the set of background colors. The index is consistent with the set number of the row number (SET index minus 1)
Public forecolor () as color 'is used to store the set of foreground views. The index is consistent with the set number of the row number.
Private function gettext (byval value as object) as string
'Read the content in textbox for repainting. This function increases fault tolerance and has nothing to do with the implementation mechanism.
If typeof (value) is system. dbnull then
Return nulltext
Elseif value is nothing then
Return ""
Else
Return Value. tostring
End if
End Function
Protected overloads overrides sub paint (_
Byval G as system. Drawing. Graphics ,_
Byval bounds as system. Drawing. rectangle ,_
Byval source as system. Windows. Forms. currencymanager ,_
Byval rownum as integer ,_
Byval backbrush as system. Drawing. Brush ,_
Byval forebrush as system. Drawing. Brush ,_
Byval aligntoright as Boolean)
Dim text as string
'Redraw in default mode
TEXT = gettext (getcolumnvalueatrow (source, rownum) 'refers to the data extraction mentioned above.
If text = "(null)" then
TEXT = ""
End if
Backbrush = new solidbrush (textbox. backcolor) 'background color
Forebrush = new solidbrush (textbox. forecolor) 'foreground color
'Prevents the user from defining the SET SIZE
Redim preserve backcolor (rowcollection. Count)
Redim preserve forecolor (rowcollection. Count)
Dim I as integer = 1' SET index starts from 1
Do While (I <= rowcollection. Count)
If rownum = Val (rowcollection. Item (I) then', the number of rows in the collection is determined to be
If not backcolor (I-1). isempty then 'is not defined, it is drawn by default color.
Backbrush = new solidbrush (backcolor (I-1 ))
End if
If not forecolor (I-1). isempty then 'is not defined, it is drawn by default color.
Forebrush = new solidbrush (forecolor (I-1 ))
End if
End if
I + = 1
Loop
Mybase. painttext (G, bounds, text, backbrush, forebrush, aligntoright)
End sub
End Class

Do While (I <numcols) 'redraws all columns
Acolumntextcolumn = new datagridcoloredtextboxcolumn
J = 0
If s_count> 0 then
For J = 0 to stopvdf. Length-1
Acolumntextcolumn. rowcollection. Add (stopvdf (j ))
Redim preserve acolumntextcolumn. forecolor (acolumntextcolumn. rowcollection. Count)
Redim preserve acolumntextcolumn. backcolor (acolumntextcolumn. rowcollection. Count)
Acolumntextcolumn. forecolor (j) = color. Gray
Acolumntextcolumn. backcolor (j) = color. White
Next
End if
If e_count> 0 then
For m = 0 to endde. Length-1
Acolumntextcolumn. rowcollection. Add (endde (m ))
Redim preserve acolumntextcolumn. forecolor (acolumntextcolumn. rowcollection. Count)
Redim preserve acolumntextcolumn. backcolor (acolumntextcolumn. rowcollection. Count)
Acolumntextcolumn. forecolor (j) = color. Red
Acolumntextcolumn. backcolor (j) = color. White
J = J + 1
Next
End if
Acolumntextcolumn. headertext = DVD. Table. Columns (I). columnname
Acolumntextcolumn. mappingname = DVD. Table. Columns (I). columnname
Acolumntextcolumn. Alignment = horizontalalignment. Center
TS. gridcolumnstyles. Add (acolumntextcolumn)
I = (I + 1)
Loop
Me. dgddelegainfo. tablestyles. Clear ()
Me. dgddelegainfo. tablestyles. Add (TS) 'datagrid

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.