VS 2003 VB .NET
I am currently trying to accomplish two things.
1. In Code, trying to set the column width
2. Trying to change the color of the row based on the value of one cell.
For the width, I thought I could do it like this:
Dim ts As DataGridTableStyle = New DataGridTableStyle
Dim daGrid1 As New SqlDataAdapter(Me.SqlCommand1)
dsGrid1 = New DataSet
dsGrid1.Clear()
daGrid1.Fill(dsGrid1, "top")
DataGrid1.DataSource = dsGrid1.Tables(0).DefaultView
DataGrid1.TableStyles.Add(ts)
DataGrid1.TableStyles(0).GridColumnStyles(1).Width = 5
This does not effect the grid at all.
2. I don't know where to start, can't find a walkthrough or article on just this.
I am needing to do both of these at run time, not design time.
Any thoughts
Thanks

Datagrid column width and row color.
BobConsultant
I have used the method you are referring to above, and successfully color one cell. I just can't get it to do the whole row from that paint method.
Umachandar Jayachandran - MS
KHadden
I'm also looking for a way to color the entire row based on the contents of a cell. If you find out, please let me know!
regthesk8r
Here are a few C# snippets. During initialization, I make a Style with the colored background:
dataGridViewCellStyle = mainDataGridView.DefaultCellStyle.Clone();
Color color = Color.FromName(theColorNode.Value);dataGridViewCellStyle.BackColor = color;
styles[theValue] = dataGridViewCellStyle;
When the row scrolls into view, I set the background color:
mainDataGridView.Rows[rowNumber].DefaultCellStyle = ((
DataGridViewCellStyle)(columnsHope this helps
Mike
jag108
Dim dts As DataGridTableStyle = New DataGridTableStyle
Dim daGrid1 As New SqlDataAdapter(Me.SqlCommand1)
dsGrid1 = New DataSet
dsGrid1.Clear()
daGrid1.Fill(dsGrid1, "top")
dts.MappingName = dsGrid1.Tables("top").TableName
Dim colTask As New DataGridTextBoxColumn
With colTask
.MappingName = "Task"
.HeaderText = "Task"
.Width = 10
End With
dts.GridColumnStyles.Add(colTask)
DataGrid1.DataSource = dsGrid1.Tables(0).DefaultView
DataGrid1.TableStyles.Add(dts)
but this is the error I am getting:
"The data grid table styles collection already contains a table style with the same mapping name."
CHEN YU-TIEN
here is what you have to do:
1 All of your column must be an instance of the custom column style class
2. You can check the value of another column in the Pain method. Thus, based on another column value, you can paint the current column with different color.
protected
override void Paint(Graphics g,Rectangle Bounds,CurrencyManager Source,int RowNum, Brush BackBrush ,Brush ForeBrush ,bool AlignToRight){
//Add this section, in this example if the value of the cell at column 1 is "TRUE", then the entire row will be red
string isvip=this.DataGridTableStyle.DataGrid[RowNum,1].ToString().ToUpper(); if(isvip=="TRUE")BackBrush = Brushes.Red;
elseBackBrush = Brushes.White;
//
}
hope this helps
~Sam
cisco0407
check this out:
http://www.windowsforms.net/FAQs/default.aspx PageID=2&ItemID=412&CategoryID=3&tabindex=3
but, this shows only how to color a particular cell based on its value. If you modify the Paint method in your custom class, you can color the entire row based on the value of one cell.
hope this helps
~Sam
Romantic_touch
All the examples I had from doing searches must not have had this issue. They showed me the proper syntax, just not this.
(Any idea on changing color for each row based on a value of one column in that row )
Thanks,
Steve
CharlieRussell
ScottPGlover
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q1075q
(5.14)
Can't get it to color the whole row, but this should work for now. If anyone has go it to color the entire row, pls reply.