تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
Get Selected Cells and Columns and rows in datagridview
#1
كاتب الموضوع : shenosheno2008


Get Selected Cells

كود :
[COLOR=#000000][COLOR=#0000bb]
    Dim selectedCellCount [/COLOR][color=#007700]As [/color][color=#0000bb]Integer [/color][color=#007700]= [/color][COLOR=#0000bb]_
        dataGridView1[/COLOR][color=#007700].[/color][color=#0000bb]GetCellCount[/color][color=#007700]([/color][color=#0000bb]DataGridViewElementStates[/color][color=#007700].[/color][color=#0000bb]Selected[/color][COLOR=#007700])

    If [/COLOR][color=#0000bb]selectedCellCount [/color][color=#007700]> [/color][COLOR=#0000bb]0 Then

        [/COLOR][color=#007700]If [/color][color=#0000bb]dataGridView1[/color][color=#007700].[/color][color=#0000bb]AreAllCellsSelected[/color][color=#007700]([/color][color=#0000bb]True[/color][color=#007700]) [/color][COLOR=#0000bb]Then

            MessageBox[/COLOR][color=#007700].[/color][color=#0000bb]Show[/color][color=#007700]([/color][color=#dd0000]"All cells are selected"[/color][color=#007700], [/color][color=#dd0000]"Selected Cells"[/color][COLOR=#007700])

        Else

            [/COLOR][color=#0000bb]Dim sb [/color][color=#007700]As New [/color][color=#0000bb]System[/color][color=#007700].[/color][color=#0000bb]Text[/color][color=#007700].[/color][color=#0000bb]StringBuilder[/color][COLOR=#007700]()

            [/COLOR][color=#0000bb]Dim i [/color][color=#007700]As [/color][COLOR=#0000bb]Integer
            [/COLOR][color=#007700]For [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]0 To selectedCellCount [/color][color=#007700]- [/color][COLOR=#0000bb]1

                sb[/COLOR][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#dd0000]"Row: "[/color][COLOR=#007700])
                [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#0000bb]dataGridView1[/color][color=#007700].[/color][color=#0000bb]SelectedCells[/color][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]).[/color][COLOR=#0000bb]RowIndex _
                    [/COLOR][color=#007700].[/color][color=#0000bb]ToString[/color][COLOR=#007700]())
                [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#dd0000]", Column: "[/color][COLOR=#007700])
                [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#0000bb]dataGridView1[/color][color=#007700].[/color][color=#0000bb]SelectedCells[/color][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]).[/color][COLOR=#0000bb]ColumnIndex _
                    [/COLOR][color=#007700].[/color][color=#0000bb]ToString[/color][COLOR=#007700]())
                [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#0000bb]Environment[/color][color=#007700].[/color][color=#0000bb]NewLine[/color][COLOR=#007700])

            [/COLOR][COLOR=#0000bb]Next i

            sb[/COLOR][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#dd0000]"Total: " [/color][color=#007700]+ [/color][color=#0000bb]selectedCellCount[/color][color=#007700].[/color][color=#0000bb]ToString[/color][COLOR=#007700]())
            [/COLOR][color=#0000bb]MessageBox[/color][color=#007700].[/color][color=#0000bb]Show[/color][color=#007700]([/color][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]ToString[/color][color=#007700](), [/color][color=#dd0000]"Selected Cells"[/color][COLOR=#007700])

        [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If

    [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If  
[/COLOR][/COLOR]

Get Selected Rows

كود :
[COLOR=#000000][COLOR=#0000bb]
  Dim selectedRowCount [/COLOR][color=#007700]As [/color][color=#0000bb]Integer [/color][color=#007700]= [/color][COLOR=#0000bb]_
        dataGridView1[/COLOR][color=#007700].[/color][color=#0000bb]Rows[/color][color=#007700].[/color][color=#0000bb]GetRowCount[/color][color=#007700]([/color][color=#0000bb]DataGridViewElementStates[/color][color=#007700].[/color][color=#0000bb]Selected[/color][COLOR=#007700])

    If [/COLOR][color=#0000bb]selectedRowCount [/color][color=#007700]> [/color][COLOR=#0000bb]0 Then

        Dim sb [/COLOR][color=#007700]As New [/color][color=#0000bb]System[/color][color=#007700].[/color][color=#0000bb]Text[/color][color=#007700].[/color][color=#0000bb]StringBuilder[/color][COLOR=#007700]()

        [/COLOR][color=#0000bb]Dim i [/color][color=#007700]As [/color][COLOR=#0000bb]Integer
        [/COLOR][color=#007700]For [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]0 To selectedRowCount [/color][color=#007700]- [/color][COLOR=#0000bb]1

            sb[/COLOR][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#dd0000]"Row: "[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#0000bb]dataGridView1[/color][color=#007700].[/color][color=#0000bb]SelectedRows[/color][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]).[/color][color=#0000bb]Index[/color][color=#007700].[/color][color=#0000bb]ToString[/color][COLOR=#007700]())
            [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#0000bb]Environment[/color][color=#007700].[/color][color=#0000bb]NewLine[/color][COLOR=#007700])

        [/COLOR][COLOR=#0000bb]Next i

        sb[/COLOR][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#dd0000]"Total: " [/color][color=#007700]+ [/color][color=#0000bb]selectedRowCount[/color][color=#007700].[/color][color=#0000bb]ToString[/color][COLOR=#007700]())
        [/COLOR][color=#0000bb]MessageBox[/color][color=#007700].[/color][color=#0000bb]Show[/color][color=#007700]([/color][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]ToString[/color][color=#007700](), [/color][color=#dd0000]"Selected Rows"[/color][COLOR=#007700])

    [/COLOR][color=#0000bb]End [/color][COLOR=#007700]If  
[/COLOR][/COLOR]

Get Select Columns


كود :
[COLOR=#000000][COLOR=#0000bb]
Dim selectedColumnCount [/COLOR][color=#007700]As [/color][color=#0000bb]Integer [/color][color=#007700]= [/color][color=#0000bb]dataGridView1[/color][color=#007700].[/color][COLOR=#0000bb]Columns _
        [/COLOR][color=#007700].[/color][color=#0000bb]GetColumnCount[/color][color=#007700]([/color][color=#0000bb]DataGridViewElementStates[/color][color=#007700].[/color][color=#0000bb]Selected[/color][COLOR=#007700])

    If [/COLOR][color=#0000bb]selectedColumnCount [/color][color=#007700]> [/color][COLOR=#0000bb]0 Then

        Dim sb [/COLOR][color=#007700]As New [/color][color=#0000bb]System[/color][color=#007700].[/color][color=#0000bb]Text[/color][color=#007700].[/color][color=#0000bb]StringBuilder[/color][COLOR=#007700]()

        [/COLOR][color=#0000bb]Dim i [/color][color=#007700]As [/color][COLOR=#0000bb]Integer
        [/COLOR][color=#007700]For [/color][color=#0000bb]i [/color][color=#007700]= [/color][color=#0000bb]0 To selectedColumnCount [/color][color=#007700]- [/color][COLOR=#0000bb]1

            sb[/COLOR][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#dd0000]"Column: "[/color][COLOR=#007700])
            [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#0000bb]dataGridView1[/color][color=#007700].[/color][color=#0000bb]SelectedColumns[/color][color=#007700]([/color][color=#0000bb]i[/color][color=#007700]).[/color][color=#0000bb]Index[/color][color=#007700].[/color][color=#0000bb]ToString[/color][COLOR=#007700]())
            [/COLOR][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#0000bb]Environment[/color][color=#007700].[/color][color=#0000bb]NewLine[/color][COLOR=#007700])

        [/COLOR][COLOR=#0000bb]Next i

        sb[/COLOR][color=#007700].[/color][color=#0000bb]Append[/color][color=#007700]([/color][color=#dd0000]"Total: " [/color][color=#007700]+ [/color][color=#0000bb]selectedColumnCount[/color][color=#007700].[/color][color=#0000bb]ToString[/color][COLOR=#007700]())
        [/COLOR][color=#0000bb]MessageBox[/color][color=#007700].[/color][color=#0000bb]Show[/color][color=#007700]([/color][color=#0000bb]sb[/color][color=#007700].[/color][color=#0000bb]ToString[/color][color=#007700](), [/color][color=#dd0000]"Selected Columns"[/color][COLOR=#007700])  
[/COLOR][/COLOR]
}}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  الرسم علي أداة DataGridView RaggiTech 0 417 17-10-12, 07:23 PM
آخر رد: RaggiTech
  عمل datagridview مربوطه بقاعده بيانات للاضافه و الحذف و التعديل فجوال بيزك RaggiTech 0 842 17-10-12, 05:10 PM
آخر رد: RaggiTech
  عمل datagridview مربوطه بقاعده بيانات للاضافه و الحذف و التعديل سي شارب RaggiTech 0 990 17-10-12, 05:10 PM
آخر رد: RaggiTech

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم