0
votes

Based on what you see below is the sample of a datagridview that an item has been selected.

enter image description here

Here is my question what if I have a more than 1 Datagridview? I mean 5 Datagridview like this.

enter image description here

All of them contains 1 column only. Based on the 1st image, the row selector or the blue one select an item.

My question is how can I make all of the datagridview only have one row selector?

What happens is when i selected each of them all of it has a row selected 5 selections.

How can I make 1 row selector for all of them.

Thinking of changing the Selection Color but I think that's not applicable.

TYSM for future help.

2
5 datagrid or more? then if you click 1st row in 1st datagrid the 2nd datagrid will also select the 1st row and so on? this is what you want to achieve?Muj
No sir, Example I click datagridview1 so there is a blue selector, If I click datagridview2 the row selector from datagridview1 will be gone because I selected a new one and so on, For example a datagridview with many columns and CellSelect SelectiondMode One row selector in all 5 datagridviewShadow Fiend
then insert clearselection for example you click datagrid1 then insert dg2.clearselection() dg3.clearselection() and so on. then if you click datagrid2 then insert dg1.clearselection() dg3.clearselection() and so on.Muj
You mean datagridview1.ClearSelection? just add this code everytime i click a cell?Shadow Fiend
yah. if you click datagridview2 then make sure that you clear the selected cell in dg1 or dg3 or dg4 and so onMuj

2 Answers

2
votes

If you're looking for an alternative, you can also try this approach:

Private Sub DataGridView_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles _
DataGridView1.CellEnter, DataGridView2.CellEnter, DataGridView3.CellEnter, DataGridView4.CellEnter, DataGridView5.CellEnter
    Dim MyDataGrids() As DataGridView = {DataGridView1, DataGridView2, DataGridView3, DataGridView4, DataGridView5}
    For i = 0 To MyDataGrids.Count - 1
        If MyDataGrids(i).Name = sender.Name Then
            Continue For
        Else
            MyDataGrids(i).ClearSelection()
        End If
    Next
End Sub

MyDataGrids() is an array of DataGridViews. If for example, the controls you need to check increases, just add the name of the DataGridView in this array and it will be included in the checking and clearing of selections. Don't also forget the Handles event. As you can see here, all of the five grids .CellEnter event are included so you don't have to copy-paste it to five separate events.

0
votes

Try this maybe it is more easy to edit if you add more grid

Private Sub ClearSelectedCells(ByVal Identifier As Integer)
    If Identifier = 1 Then 'for datagrid 1
        dg2.ClearSelection()
        dg3.ClearSelection()
    ElseIf Identifier = 2 Then 'for datagrid 2
        dg1.ClearSelection()
        dg3.ClearSelection()
    'and so on
    .
    .
    End If
End Sub


Private Sub dg1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dg1.CellClick
    ClearSelectedCells(1)
End Sub

'and other gridcellclick
.
.