Disable cell-border highlight DataGridView - vb.net

I'm trying to disable the border around a cell when selected! (The black rectangle, not the blue background).
Is that possible?
this is my grid initialization code (maybe will help):
With DBGrid
.RowHeadersVisible = False
.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
.RowTemplate.Height = internal_RowHeight
' Set property values appropriate for read-only display and
' limited interactivity.
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = False
.ReadOnly = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.AllowUserToResizeColumns = False
.AllowUserToResizeRows = False
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
' Set the row height
.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
.ColumnHeadersHeight = internal_RowHeight
.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
' Set the selection background color for all the cells.
.DefaultCellStyle.BackColor = internal_BackColor
.DefaultCellStyle.ForeColor = internal_ForeColor
.DefaultCellStyle.SelectionBackColor = internal_BackColorSel
.DefaultCellStyle.SelectionForeColor = internal_ForeColorSel
' Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
' value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Empty
.RowsDefaultCellStyle.BackColor = Color.Empty
' Set the row and column header styles.
.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
.ColumnHeadersDefaultCellStyle.BackColor = Color.Black
End With

Since you want to disable the active cell, I would assume you only intend to use the grid as a way to select a row and not edit the contents.
In that case, use the following settings:
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.ReadOnly = True

Related

How can I remove the cell selection from a checkbox column ? VB.NET

Greetings to the community.
I am trying to modify a checkbox column of a DataGridView in VB.NET. I hope you can help me.
I am looking to go from this:
To this:
That is, even if I click or double click on the cell, the checkbox is not selected.
Part of the code where the columns are added to DataGridView (DvgNeumaticos):
If BtnVistaPorFacturar.Checked Then
For i As Integer = 0 To DgvNeumaticos.Columns.Count - 1
DgvNeumaticos.Columns(i).Visible = False
Next
DgvNeumaticos.Columns("ColChk").Visible = True
DgvNeumaticos.Columns("CodOS").Visible = True
DgvNeumaticos.Columns("Tipo").Visible = True
DgvNeumaticos.Columns("NroOrden").Visible = True
DgvNeumaticos.Columns("NroOrden").DisplayIndex = 0
DgvNeumaticos.Columns("FechaOS").Visible = True
DgvNeumaticos.Columns("F.Cierre").Visible = True
DgvNeumaticos.Columns("Observacion").Visible = True
DgvNeumaticos.Columns("CodNeumatico").Visible = True
DgvNeumaticos.Columns("Externo").Visible = True
DgvNeumaticos.Columns("CodTercero").Visible = True
DgvNeumaticos.Columns("CodProducto").Visible = True
DgvNeumaticos.Columns("Producto").Visible = True
DgvNeumaticos.Columns("Trabajo").Visible = True
DgvNeumaticos.Columns("NroDocRecepcion").Visible = True
DgvNeumaticos.Columns("FechaRecepcion").Visible = True
New Edit:
If BtnVistaPorFacturar.Checked Then
Dim chkCol As New DataGridViewCheckBoxColumn
chkCol.Name = "ColChk"
chkCol.HeaderText = "Chk"
DgvNeumaticos.Columns.Add(chkCol)
dt = WFOrdServicioNeumaticos.Instancia.fdu_NEUM_ORDSERV_VerOrdenesPorFacturar(.Cells("IDAgente").Value)
End If
Thanks for the replies.

displayindex datatable/dgv columns not working

I set up some datatables via the Visual Studio table/columns collection editor. Sadly, it appears MS didn't include any way to re-order the data columns in the collection editor once you've done (no up/down facility). Thus, I'm having to programmatically re-order my columns (as out of order in the collection).
Done a lot of reading on this and for the life of me, can't locate the source of the problem. Basically, despite the code below, the datacolumns still show out-of-order on the datagridview. Code (abridged):
Private Sub LoadTextStylesDGV()
With _TextStylesDGV
.DefaultCellStyle.Padding = New Padding(0, 5, 0, 5)
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToResizeColumns = True
.Columns.Add(New DataGridViewComboBoxColumn With {.DataPropertyName = "TextAlign", .Visible = True,
.Name = "TextAlign",
.HeaderText = "TextAlign",
.DataSource = MarqueeEditor._EnumDDContentAlign,
.FlatStyle = FlatStyle.Flat,
.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells})
' And other column setups similar to above
' ....
.DataSource = Global.CPWBAdmin.MarqueeEditor.MarqueeData.Tables("TextStyles")
.MultiSelect = False
.AllowUserToDeleteRows = False
With .Columns("ID")
.ReadOnly = True
.DefaultCellStyle.BackColor = Color.LightGray
.Visible = False
.DisplayIndex = 0
.Frozen = True
End With
With .Columns("Name")
.DisplayIndex = 1
.Frozen = True
.DefaultCellStyle.BackColor = Color.Linen
End With
.Columns("RandomStyle?").DisplayIndex = 2
With .Columns("Font")
.ReadOnly = True
.DefaultCellStyle.BackColor = Color.LightBlue
.AutoSizeMode = DataGridViewAutoSizeColumnMode.None
.DisplayIndex = 3
End With
'.... other column display index settings
.Columns("Stroke3LineJoin").DisplayIndex = 49
.Columns("Stroke3Wrap").DisplayIndex = 50
.Columns("TextAutoFit").DisplayIndex = 51
'Sort:
.Sort(_TextStylesDGV.Columns("Name"), System.ComponentModel.ListSortDirection.Ascending)
End With
End Sub
I'm wondering whether the DGV columns are getting re-ordered elsewhere in the code. Of course - no way to check this with step-by-step debugging as happens before form show. Have trawled through the code but can't see anything obvious. Does anyone have any ideas as this one is killing me! If only MS had allowed column collection re-ordering. :(
Oooops. Didn't search hard enough! Finally found the solution:
dgvReservedStalls.AutoGenerateColumns = True
dgvReservedStalls.DataSource = clsReservedStalls.LoadDataTable()
dgvReservedStalls.AutoGenerateColumns = False
auto generates the columns from the DT, then frees it for re-ordering the columns. A little obscure, MS... :)
From here

Programmatically change "Don't add space between paragraphs of the same style"

I'm trying to programmatically change "Don't add space between paragraphs of the same style." To approach the problem, I recorded a macro during which I opened the Paragraph dialog box (Page Layout > Paragraph), checked the checkbox (don't add space) and a macro during which I unchecked the checkbox (add space). Neither affects "Don't add space between paragraphs of the same style" . . . and they have identical code:
Sub AddSpaceBetweenParagraphsOfSameStyle()
'
' AddSpaceBetweenParagraphsOfSameStyle Macro
' Add space between paragraphs of the same style.
'
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 12
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(-0.25)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
Sub RemoveSpaceBetweenParagraphsOfSameStyle()
'
' RemoveSpaceBetweenParagraphsOfSameStyle Macro
' Remove space between paragraphs of the same style.
'
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 12
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(-0.25)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
End With
End Sub
The code produced by the macro recorder is long, so I reduced it to a minimal version that I've verified also fails to affect "Don't add space between paragraphs of the same style":
Sub AddSpaceBetweenParagraphsOfSameStyle()
'
' AddSpaceBetweenParagraphsOfSameStyle Macro
' Add space between paragraphs of the same style.
'
End Sub
Sub RemoveSpaceBetweenParagraphsOfSameStyle()
'
' RemoveSpaceBetweenParagraphsOfSameStyle Macro
' Remove space between paragraphs of the same style.
'
End Sub
I looked at the documentation for ParagraphFormat and searched for a relevant property but found nothing that works. How can I programmatically change "Don't add space between paragraphs of the same style"?
This property is connected with Style, not with Paragraph (which suggests window title where you set this property). This is code which you look for:
ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle = False
ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle = True
The macro recorder recognizes changing spacing but not "Don't add space between paragraphs of the same style" (Page Layout > Paragraph). To change paragraph formatting without modifying a built-in style (or creating a new style), I can use Selection.Style:
Selection.Style.NoSpaceBetweenParagraphsOfSameStyle = False
or fall back to the built-in dialog:
With Dialogs(wdDialogFormatParagraph)
.Before = 12
.After = 12
.NoSpaceBetweenParagraphsOfSameStyle = False
.Execute
End With
winword.ActiveDocument.Styles["Normal"].NoSpaceBetweenParagraphsOfSameStyle = true;
winword.ActiveDocument.Styles["List Paragraph"].NoSpaceBetweenParagraphsOfSameStyle = false;
On word doc press Alt+Ctl+Shift+S to check all the styles
If anyone stumbles on this and is looking for a C# example, this is what worked for me. Hope it helps someone else.
string signaturesPath = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + #"\Microsoft\Signatures\";
Directory.CreateDirectory(signaturesPath + "Test");
Word.Application oWord = new Word.Application();
//oWord.Visible = true;
Word.Document oDoc = oWord.Documents.Add();
//Insert a paragraph at the beginning of the document.
Word.Paragraph paragraph1 = oDoc.Content.Paragraphs.Add();
object oStyleName1 = Word.WdBuiltinStyle.wdStyleNormal;
//NoSpaceBetweenParagraphsOfSameStyle set on style then assign to doc
oWord.ActiveDocument.Styles[oStyleName1].NoSpaceBetweenParagraphsOfSameStyle = true;
//Setting style on paragraph here
paragraph1.Format.set_Style(oStyleName1);
paragraph1.Range.Font.Bold = 1;
paragraph1.Range.InsertAfter("Testing 123");
//Save as htm
object htmlFormat = (int)Word.WdSaveFormat.wdFormatFilteredHTML;
oDoc.SaveAs2(signaturesPath + #"\test.htm", htmlFormat);
oWord.Quit();

Selected row flickers when scrolling

I have bounded DataGridView with 5000 rows of data in Form where dgv "fill" forms area.
When I scroll it with keyboard up or down selected row flickers much on solid computer.
Is here a way to get rid of that flickering?
Here is how my DataGridView is setup:
With DataGridView1
.AllowUserToAddRows = False
.AllowDrop = False
.AllowUserToOrderColumns = False
.AllowUserToResizeRows = False
.ColumnHeadersDefaultCellStyle.Font = fnt1
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.ScrollBars = ScrollBars.Vertical
.MultiSelect = False
.ReadOnly = True
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
.GridColor = Color.FromArgb(240, 240, 240)
.DefaultCellStyle.Font = fnt1
.BorderStyle = BorderStyle.None
.Dock = DockStyle.Fill
End With
You can get rid of the flickering by implementing double buffering for that form
me.SetStyle(
ControlStyles.AllPaintingInWmPaint OR _
ControlStyles.UserPaint OR _
ControlStyles.DoubleBuffer,true)
This should work
try this then
i really hope it helps

Gridview Show and Hide a Specific Column

I have a gridview in which a specific column Date. I have set the Visible property of column to false because I want to show on different conditions of page. Please tell me how can I do it using vb.net that my Date column should show or hide at runtime
Update
My current code is
If Not Page.User.Identity.Name = "bilal" Then
GridView1.AutoGenerateEditButton = False
GridView2.AutoGenerateEditButton = False
GridView3.AutoGenerateEditButton = False
Else
GridView1.AutoGenerateEditButton = True
GridView1.AutoGenerateColumns = True
GridView1.DataBind()
If GridView1.Columns.Count > 0 Then
'assuming your date-column is the first '
GridView1.Columns(3).Visible = True
Else
GridView1.HeaderRow.Cells(0).Visible = False
For Each gvr As GridViewRow In GridView1.Rows
gvr.Cells(0).Visible = True
Next
End If
GridView2.AutoGenerateEditButton = True
GridView3.AutoGenerateEditButton = True
End If
If you've set AutoGenerateColumns to True, the Column-Count will be 0, then you need to loop the rows and show/hide the appropriate cells. Otherwise you can use the Visible property.
GridView1.DataBind()
If GridView1.Columns.Count > 0 Then
'assuming your date-column is the 4.'
GridView1.Columns(3).Visible = True
Else
GridView1.HeaderRow.Cells(3).Visible = False
For Each gvr As GridViewRow In GridView1.Rows
gvr.Cells(3).Visible = True
Next
End If