|
I want to set different color for controls between lineswith DrawItemevent, everything is ok when the form first displayed, but if I drag the scrollbar up and down or click any line, all rows finallyturn tosame color. As follows
Private Sub DataRepeater1_DrawItem(ByVal sender As System.Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles datarep.DrawItem If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then DirectCast(e.DataRepeaterItem.Controls("lblPage"), Label).BackColor = Color.Yellow DirectCast(e.DataRepeaterItem.Controls("lblTel1"), Label).BackColor = Color.Yellow . . . End If End Sub
Can anyone tell me why? | | SimonTang1113 Friday, September 18, 2009 12:58 PM | Hi Simon, Yes, I can answer your question. :-). You need to handle the else case for If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then Like this: If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then DirectCast(e.DataRepeaterItem.Controls("lblPage"), Label).BackColor = Color.Yellow DirectCast(e.DataRepeaterItem.Controls("lblTel1"), Label).BackColor = Color.Yellow . . else . DirectCast(e.DataRepeaterItem.Controls("lblPage"), Label).BackColor = Color.White ' or what ever color oringinally End If Please read my blog here: http://blogs.msdn.com/vsdata/archive/2009/09/08/writing-event-handler-for-controls-in-a-datarepeateritem.aspxCheers!
John Chen
-- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
- Marked As Answer bySimonTang1113 Saturday, September 19, 2009 8:43 AM
-
| | John Chen MS Friday, September 18, 2009 6:26 PM | Hi Simon, This is also noted in the topic for the DrawItem event: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.datarepeater.drawitem.aspx"If you set a property in a conditional statement such as If…Then, you must also use an Else clause to specify the appearance when the condition is not met." Also note that it's not necessary to use DirectCast - you can reference Control.Name to get to the properties: e.DataRepeaterItem.Controls(lblPage.Name).BackColor = Color.Yellow Hope this helps,
Steve Hoag
Microsoft
aka the V-Bee - Marked As Answer bySimonTang1113 Saturday, September 19, 2009 8:43 AM
-
| | shoagMSFT Friday, September 18, 2009 7:54 PM | Steve got an official answer. I like Controls(lblPage.Name)
John Chen
-- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
- Marked As Answer bySimonTang1113 Saturday, September 19, 2009 8:45 AM
-
| | John Chen MS Friday, September 18, 2009 8:16 PM | Hi Simon, Yes, I can answer your question. :-). You need to handle the else case for If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then Like this: If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then DirectCast(e.DataRepeaterItem.Controls("lblPage"), Label).BackColor = Color.Yellow DirectCast(e.DataRepeaterItem.Controls("lblTel1"), Label).BackColor = Color.Yellow . . else . DirectCast(e.DataRepeaterItem.Controls("lblPage"), Label).BackColor = Color.White ' or what ever color oringinally End If Please read my blog here: http://blogs.msdn.com/vsdata/archive/2009/09/08/writing-event-handler-for-controls-in-a-datarepeateritem.aspxCheers!
John Chen
-- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
- Marked As Answer bySimonTang1113 Saturday, September 19, 2009 8:43 AM
-
| | John Chen MS Friday, September 18, 2009 6:26 PM | Hi Simon, This is also noted in the topic for the DrawItem event: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.datarepeater.drawitem.aspx"If you set a property in a conditional statement such as If…Then, you must also use an Else clause to specify the appearance when the condition is not met." Also note that it's not necessary to use DirectCast - you can reference Control.Name to get to the properties: e.DataRepeaterItem.Controls(lblPage.Name).BackColor = Color.Yellow Hope this helps,
Steve Hoag
Microsoft
aka the V-Bee - Marked As Answer bySimonTang1113 Saturday, September 19, 2009 8:43 AM
-
| | shoagMSFT Friday, September 18, 2009 7:54 PM | Steve got an official answer. I like Controls(lblPage.Name)
John Chen
-- See my team blog: http://blogs.msdn.com/vsdata. All my posts are provided "AS IS" with no warranties, and confer no rights.
- Marked As Answer bySimonTang1113 Saturday, September 19, 2009 8:45 AM
-
| | John Chen MS Friday, September 18, 2009 8:16 PM | hi, many thanks to all of you, I have finished my job, this powerful control is really wonderful!!! | | SimonTang1113 Saturday, September 19, 2009 8:41 AM |
|