displayindex datatable/dgv columns not working - vb.net

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

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.

How do I show multiple legends on a VB.Net Chart

My code creates a MS Chart with one or more ChartAreas and I want to have a separate legend for each ChartArea
My code is as below:
For tblNum = 0 To (dsData.Tables.Count - 1)
tblName = dsData.Tables(tblNum).TableName
caTag = dtReport.Rows(tblNum).Item("caTag")
If (dtReport.Rows(tblNum).Item("CAnum") > CAnum) Then
CAnum = dtReport.Rows(tblNum).Item("CAnum")
myChart.ChartAreas.Add(caTag)
myChart.Legends.Add(caTag)
With myChart.Legends(caTag)
.Docking = Docking.Bottom
.DockedToChartArea = caTag
.IsDockedInsideChartArea = False
.TableStyle = LegendTableStyle.Wide
.Alignment = StringAlignment.Center
.Enabled = True
End With
If (caCount > 1) Then
CAindex += 1
myChart.Titles.Add(caTag)
With myChart.Titles(CAindex)
.Docking = Docking.Top
.DockedToChartArea = caTag
.IsDockedInsideChartArea = False
.Alignment = ContentAlignment.TopCenter
.Font = New System.Drawing.Font("Times New Roman", 14, FontStyle.Bold)
.Text = caTag
End With
End If
Else
myChart.Legends(caTag).Enabled = True
End If
However when I run the code only a single Legend is visible containing all series from both ChartAreas as below:
Legend-1.jpg
Can anyone help me please ?
I have found the answer to my own question.
I needed to assign the correct legend to each series as follows:
myChart.Series(tblName).Legend = caTag
Now both legends are shown with the appropriate series names

Assign value to checkboxes

Hye there, I new with vba here.
I want to use checkboxes to link with the series collections of a chart. I put the check boxes in a sheet which contain the chart altogether. I have a lot of checkboxes here to be assigned to "true" value.
Private Sub Controls_Initialize()
'Make default for checkboxes
CheckBox1.Value = True
CheckBox2.Value = True
CheckBox3.Value = True
CheckBox4.Value = True
CheckBox5.Value = True
CheckBox6.Value = True
CheckBox7.Value = True
CheckBox8.Value = True
CheckBox9.Value = True
CheckBox10.Value = True
CheckBox11.Value = True
CheckBox12.Value = True
CheckBox13.Value = True
CheckBox14.Value = True
CheckBox15.Value = True
CheckBox16.Value = True
CheckBox17.Value = True
CheckBox18.Value = True
CheckBox19.Value = True
CheckBox20.Value = True
CheckBox21.Value = True
CheckBox22.Value = True
CheckBox23.Value = True
CheckBox24.Value = True
End Sub
I have tried this code but can't
For i = 1 to 24
Controls("CheckBox" & i).Value = True
Next i
The questions are
1. Is there any other code that can make it simple?
2. How to link the check boxes with the series collection in the activechart? Example, if the checkbox return value false, the series collection will be deleted/hide(perhaps?). And when it returns value true, the series collection of the same data will be added back in the chart. I would like to make the chart interactive.
If there is any reference that I can reviewed, do tell me.
Thanks in advance.
Regards.
Alright, so assuming from what you've given, I'd think the problem is that the interpreter doesn't know i is an integer.
To fix this, we can implement something along the lines of Dim i As Integer to implement i as an integer.
We could try this:
Dim i As Integer
For i = 1 to 24
Controls("CheckBox" & i).Value = True
Next i

Disable cell-border highlight DataGridView

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

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