Hello guys , i have a gridview with 4 columns , what i want is to color just column named Color , i finded a code but color every single cell of the row and i don’t want this. The code it’s attached below photo!
,
import rhinoscriptsyntax as rs
import scriptcontext as sc
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import sqlite3
class PLATE(forms.Dialog):
# Initializer
def __init__(self):
self.Size = drawing.Size(380,200)
self.mainlay = forms.PixelLayout()
self.stock_grid = forms.GridView()
self.stock_grid.ShowHeader = True
column1 = forms.GridColumn()
column1.HeaderText = 'Stock'
column1.Width = 110
column1.Editable = False
column1.DataCell = forms.TextBoxCell(0)
self.stock_grid.Columns.Add(column1)
column2 = forms.GridColumn()
column2.HeaderText = 'Thickness'
column2.Editable = False
column2.DataCell = forms.TextBoxCell(1)
self.stock_grid.Columns.Add(column2)
column3 = forms.GridColumn()
column3.HeaderText = 'Material'
column3.Editable = False
column3.Width = 110
column3.DataCell = forms.TextBoxCell(2)
self.stock_grid.Columns.Add(column3)
column4 = forms.GridColumn()
column4.HeaderText = 'Color'
column4.Editable = False
column4.Width = 60
column4.DataCell = forms.TextBoxCell(3)
self.stock_grid.Columns.Add(column4)
self.mainlay.Add(self.stock_grid,0,0)
self.Content = self.mainlay
self.stock_grid.DataStore = [['PL AL-H111 T1', '1.0', 'Aluminium H111', '66'], ['PL AL-H111 T2', '2.0', 'Aluminium H111', '95'], ['PL AL-H111 T3', '3.0', 'Aluminium H111', '93'], ['PL AL-H111 T4', '4.0', 'Aluminium H111', '141'], ['PL AL-H111 T5', '5.0', 'Aluminium H111', '155'], ['PL AL-H111 T6', '6.0', 'Aluminium H111', '203'], ['PL AL-H111 T7', '7.0', 'Aluminium H111', '8'], ['PL AL-H111 T8', '8.0', 'Aluminium H111', '215'], ['PL AL-H111 T9', '9.0', 'Aluminium H111', '57'], ['PL AL-H111 T10', '10.0', 'Aluminium H111', '241'], ['PL AL-H111 T11', '11.0', 'Aluminium H111', '199'], ['PL AL-H111 T12', '12.0', 'Aluminium H111', '133'], ['PL AL-H111 T13', '13.0', 'Aluminium H111', '13'], ['PL AL-H111 T14', '14.0', 'Aluminium H111', '44'], ['PL AL-H111 T15', '15.0', 'Aluminium H111', '167']]
self.DictStocks = [{'SIND': '66', 'SNAME': 'PL AL-H111 T1', 'SRGB': '(95,127,0)', 'SMAT': 'Aluminium H111', 'ID': 1, 'ST': '1.0'}, {'SIND': '95', 'SNAME': 'PL AL-H111 T2', 'SRGB': '(76,153,76)', 'SMAT': 'Aluminium H111', 'ID': 2, 'ST': '2.0'}, {'SIND': '93', 'SNAME': 'PL AL-H111 T3', 'SRGB': '(102,204,102)', 'SMAT': 'Aluminium H111', 'ID': 3, 'ST': '3.0'}, {'SIND': '141', 'SNAME': 'PL AL-H111 T4', 'SRGB': '(127,223,255)', 'SMAT': 'Aluminium H111', 'ID': 4, 'ST': '4.0'}, {'SIND': '155', 'SNAME': 'PL AL-H111 T5', 'SRGB': '(76,114,153)', 'SMAT': 'Aluminium H111', 'ID': 5, 'ST': '5.0'}, {'SIND': '203', 'SNAME': 'PL AL-H111 T6', 'SRGB': '(178,102,204)', 'SMAT': 'Aluminium H111', 'ID': 6, 'ST': '6.0'}, {'SIND': '8', 'SNAME': 'PL AL-H111 T7', 'SRGB': '(128,128,128)', 'SMAT': 'Aluminium H111', 'ID': 7, 'ST': '7.0'}, {'SIND': '215', 'SNAME': 'PL AL-H111 T8', 'SRGB': '(153,76,153)', 'SMAT': 'Aluminium H111', 'ID': 8, 'ST': '8.0'}, {'SIND': '57', 'SNAME': 'PL AL-H111 T9', 'SRGB': '(127,127,63)', 'SMAT': 'Aluminium H111', 'ID': 9, 'ST': '9.0'}, {'SIND': '241', 'SNAME': 'PL AL-H111 T10', 'SRGB': '(255,127,159)', 'SMAT': 'Aluminium H111', 'ID': 10, 'ST': '10.0'}, {'SIND': '199', 'SNAME': 'PL AL-H111 T11', 'SRGB': '(57,38,76)', 'SMAT': 'Aluminium H111', 'ID': 11, 'ST': '11.0'}, {'SIND': '133', 'SNAME': 'PL AL-H111 T12', 'SRGB': '(102,204,204)', 'SMAT': 'Aluminium H111', 'ID': 12, 'ST': '12.0'}, {'SIND': '13', 'SNAME': 'PL AL-H111 T13', 'SRGB': '(204,102,102)', 'SMAT': 'Aluminium H111', 'ID': 13, 'ST': '13.0'}, {'SIND': '44', 'SNAME': 'PL AL-H111 T14', 'SRGB': '(153,114,0)', 'SMAT': 'Aluminium H111', 'ID': 14, 'ST': '14.0'}, {'SIND': '167', 'SNAME': 'PL AL-H111 T15', 'SRGB': '(63,79,127)', 'SMAT': 'Aluminium H111', 'ID': 15, 'ST': '15.0'}]
self.stock_grid.CellFormatting += self.OnCellFormatting
def SearchInDict(self,index):
to_return = None
if self.DictStocks:
for stock in self.DictStocks:
if stock["SIND"] == index:
to_return = stock["SRGB"]
break
return to_return
def OnCellFormatting(self, sender, e):
try:
target = self.stock_grid.DataStore[e.Row][3]
color = eval(self.SearchInDict(target))
color = drawing.Color.FromArgb(color[0],color[1],color[2])
e.BackgroundColor = color
except Exception as e:
print e
dialog = PLATE()
dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)