Reset Datagridview SelectionBackColor - vb.net

In my code I have need to turn the SelectionBackColor to red to notify the user of something. When that has been rectified I wish to set it again back to its default (Blue with white text). I use color.empty but this seams to not work correctly. It resets the color BUT subsequent repeat changes to SelectionBackColor are not implemented.
I use this to change it Me.DataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red
and this to reset Me.DataGridView1.DefaultCellStyle.SelectionBackColor = Color.Empty
But as I said subsequent attempts to change the color fails, even when done on the same cell that worked the first time. As I said above it's as if Im not resenting correctly. OR is it that this can only be changed once? Unlikely though
EDIT:
I tried to change the color to green instead of empty and that has worked correctly, several times over changing the color from red to green as expected. So it is definitely an issue with the color.empty (trying to reset it to default) and not code or logic anywhere else.
Thanks for any thoughts you may have
Edit2: Is there a way to capture the default style and then recall it? So instead changing to green I change to the saved default style?

the answer I found by trial and error to reset the SelectionBackColor is to first capture it and then use it when resetting.
Dim GridBackcolor As Object
GridBackcolor = Me.DataGridView1.DefaultCellStyle.SelectionBackColor
'set another color
Me.DataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red
'reset
Me.DataGridView1.DefaultCellStyle.SelectionBackColor = GridBackcolor
in case it helps anyone.

for me, the solution was to set:
.DefaultCellStyle.SelectionBackColor
AND
.DefaultCellStyle.SelectionForeColor
switch to custom colors and back worked allready....
BUT
the 2. switch dosent changed the selection color. also not the background and forecolor...
perhaps the datagridview "think" one of them (selectionforecolor, selectionbackcolor, background, forecolor) could be the "same" color and has a problem with switching them ... ?
cheers :-)

Related

How to change paddingStart and paddingEnd of the new Google Slider view

As the title says, I would like to control the padding start and padding end (the red rectangle)
I've scanned the doc but nothing come out.
https://material.io/components/sliders/android#discrete-slider
Do you guy have any idea to change it?
You have to by-pass the code here.
<dimen name="mtrl_slider_track_side_padding">0dp</dimen>

Change backcolor of DataGridViewButtonCell

I've created a DataGridViewButtonCell in this way:
For i As Integer = 0 To dgvHouse.Rows.Count - 1
dgvHouse.Rows(i).Cells(3) = New DataGridViewButtonCell()
End For
Now I want to change backcolor of these DataGridViewButtonCell.
I've tried to do this in the following way:
dgvHouse.Rows(i).Cells(3).Style.BackColor = Color.Red
But this change backcolor of cell not of the DataGridViewButtonCell
How can I do that? How can I access to a specific DataGridViewButtonCell
"But this change backcolor of cell not of the DataGridViewButtonCell". That's actually a nonsensical statement. "the cell" is a DataGridViewButtonCell and that code changes the background colour of it. The problem is that you can't see the background of the cell because it has a rendering of a button over it. That rendering is based on system settings. You'll find that you can see the background colour if you change the FlatStyle property to certain values. If that result isn't enough, you'll need to create a custom column with custom cells that render the way you want.
Note that, if you want something to affect every cell in the column, make the change on the column, via the DefaultCellStyle property.

Change The Color Of a Row in a DataGrid to the Color Red

I have a datagrid populated with about 5 rows, and I need to change
the background color of one entire row to the color red.
This sounds easy, but I am hard pressed to find a way to do so...
I am using VB.Net with Winforms, and the option to switch to datagridview is a bit much for a color change but if that's the only option...
But was unable to use it correctly. Any ideas? If I need to be more descriptive please ask! Thank you.
You do it like this:
DataGridView1.Rows(x).DefaultCellStyle.BackColor = Color.Red'or whatever color you want, x is your row index

VB.NET MENUSTRIP doesnt honor ImageScaling at runtime

I am trying to implement a 'Flag' w/ a menustrip.
I have an image list w/ a red flag and a black flag.
When I click the menu item, i want to toggle the image.
The problem I have is that once I change the image, it wants to do SizeToFit which makes the Icon roughly the height of text. I dont want that. I want the Image to be its actual size.
I have tried putting the statements in different orders, nothing i have tried seems to work.
Currently, I have the button set to the black flag at design time.
This code shows me trying to change to a Red flag.
tsbFlagPatient.Image = ilFlags.Images(1)
tsbFlagPatient.ImageScaling = ToolStripItemImageScaling.None
tsbFlagPatient.DisplayStyle = ToolStripItemDisplayStyle.Image
[If there is some better way to approach toggling the image, im open to that. That seems like a separate question. ]
I was unable to make ImageScrolling work.
Since I dont need text here, I used BackGround Image and set
BackgroundImageLayout = Stretch
This allows the images to be the right size.
You can turn AutoSize = false and then manually set Height, Width to fine tune your menu's size.
I did reconsider the ImageList and changed the images to being stored in the project Resources. This is the code to toggle the image
Public Sub SetFlagImage(flagSet As Boolean)
If flagSet = False Then
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_black
btnFlag.BackgroundImage.Tag = "black"
Else
btnFlag.BackgroundImage = My.Resources.appbar_flag_wavy_red
btnFlag.BackgroundImage.Tag = "red"
End If
End Sub
This had no effect on the question posed here. In general, probably better than having an image list because all forms can access it.

Scroll FlowPanel scrollbar with a Trackbar

I have a FlowLayoutPanel1 in my form with a bunch of buttons inside it. I wanted to change the way its scroll bar looked so I added a TrackBar1 hoping to make it look better. I can't figure out how to do it.
I tried:
Panel1.AutoScroll.value = TrackBar1.Value
But it gives the error:
'value' is not a member of Boolean
What have I done wrong in this code?
Your code is wrong. Change it to
Panel1.HorizontalScroll.Value = TrackBar1.Value
Here, Panel1.AutoScroll only tells you if it's True or False.
I got it guys. I should've put .VerticalScroll.Value instead of AutoScroll.Value.
Panel1.VerticalScroll.Value = TrackBar1.Value
This worked.
As others have already mentioned, Panel1.AutoScroll is a boolean. You need to use HorizontalScroll.Value or VerticalScroll.Value whichever matches your requirement.