Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Forum översikt / inlägg

Posta nytt inlägg


VB.NET

Postades av 2013-02-06 22:48:06 - Torbjörn Karlberg, i forum vb.net, Tråden har 2 Kommentarer och lästs av 2742 personer

Hej
Sitter och leker lite med vb 2010 express och försöker få en sökning från en access databas som ska visas i en DataGridView1 eller liknade MSFlexGrid i vb6.

Någon som har ett enkelt exempel på hur man ska göra, får inte till det har letat på nätet men hittar inget som jag kan förstå!!!!

Vill enbart se hur man ska göra för att söka efter ett värde i en tabell som ska visar i en DataGridView.

Någon här som har ett litet exempel som man kan börja lära sig skiljer sig mycket från VB6 som jag är van vid eller inte ?

Hälsningar
Tobbe


Svara

Sv: VB.NET

Postades av 2013-02-09 00:06:25 - Pelle Johansson

Hej Torbjörn, se detta inlägg http://www.pellesoft.se/thread/214245/fyll-en-datagrid-i-vbnet


Svara

Sv:VB.NET

Postades av 2013-03-16 18:52:22 - Torbjörn Karlberg

Gjorde så här alltid någon som kan ha till hjälp ?

Public Sub Flexgrid()
        Dim conn As New OleDb.OleDbConnection
        Dim da As New OleDb.OleDbDataAdapter
        Dim ds As New DataSet
        Dim x As Integer
        Dim i As Integer
        Dim sDate As String
        Try

            Me.DataGridView1.Rows.Clear()


            Me.DataGridView1.RowCount = 30
            Me.DataGridView1.ColumnCount = 15


            With DataGridView1.ColumnHeadersDefaultCellStyle
                .BackColor = Color.Navy
                .ForeColor = Color.White
                .Font = New Font(DataGridView1.Font, FontStyle.Bold)
            End With



            ' Create an unbound DataGridView by declaring a column count.
            ' DataGridView1.ColumnCount = 13
            DataGridView1.ColumnHeadersVisible = True
            ' Set the column header style. 
            Dim columnHeaderStyle As New DataGridViewCellStyle()



            ' columnHeaderStyle.BackColor = Color.Beige
            columnHeaderStyle.Font = New Font("Verdana", 8, FontStyle.Bold)
            DataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle

            For Each row In DataGridView1.Rows
                If Not row.index / 2 = Int(row.index / 2) Then
                    row.defaultcellstyle.backcolor = Color.Azure
                End If
            Next



            DataGridView1.SelectionMode = _
                DataGridViewSelectionMode.FullRowSelect
            DataGridView1.MultiSelect = False

            ' Set the column header names.

            ' Me.DataGridView1.Columns(0).HeaderText = "ID"
            Me.DataGridView1.Columns(1).HeaderText = "Regnr"
            Me.DataGridView1.Columns(2).HeaderText = "Datum"
            Me.DataGridView1.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(3).HeaderText = "Tid"
            Me.DataGridView1.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(4).HeaderText = "Tekniker"
            Me.DataGridView1.Columns(5).HeaderText = "System"
            Me.DataGridView1.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(6).HeaderText = "Delar"
            Me.DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(7).HeaderText = "Mottagen"
            Me.DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(8).HeaderText = "Påbörjad"
            Me.DataGridView1.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(9).HeaderText = "Påbörjad tid"
            Me.DataGridView1.Columns(10).HeaderText = "Avbryten"
            Me.DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(11).HeaderText = "Klar"
            Me.DataGridView1.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            Me.DataGridView1.Columns(12).HeaderText = "Utlämnad"
            Me.DataGridView1.Columns(13).HeaderText = "Avdelning"


            Me.DataGridView1.Columns(0).Visible = False
            ' Me.DataGridView1.Columns(0).Width = 40
            Me.DataGridView1.Columns(1).Width = 60
            Me.DataGridView1.Columns(2).Width = 80
            Me.DataGridView1.Columns(3).Width = 40
            Me.DataGridView1.Columns(4).Width = 170
            Me.DataGridView1.Columns(5).Width = 70
            Me.DataGridView1.Columns(6).Width = 80
            Me.DataGridView1.Columns(7).Width = 80
            Me.DataGridView1.Columns(8).Width = 80
            Me.DataGridView1.Columns(9).Width = 120
            Me.DataGridView1.Columns(10).Width = 80
            Me.DataGridView1.Columns(11).Width = 40
            Me.DataGridView1.Columns(12).Width = 130
            Me.DataGridView1.Columns(13).Width = 146
            Me.DataGridView1.Columns(14).Visible = False

            sDate = MonthCalendar1.SelectionStart.ToShortDateString

            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & Application.StartupPath & "\Db\Bokning.mdb"

            Dim cmd As New OleDbCommand
      
            cmd.CommandText = "SELECT [ID], [Regnr], [Datum], [BokTime], [Mek], [System], [Fplock], [Start], [Status], [Mott], [Avb], [Klar], [Utl], [Avd]  FROM [Tider] where [Datum] = '" & MonthCalendar1.SelectionStart.ToShortDateString & "' and Avd = '" & ToolStripStatusLabel2.Text & "'"

            cmd.Connection = conn

            conn.Open()

            Dim rdr As OleDbDataReader = cmd.ExecuteReader

            x = 30

            For i = 0 To x

                With (rdr.Read)

                    Me.DataGridView1.Rows(i).Cells(0).Value = rdr("ID").ToString
                    Me.DataGridView1.Rows(i).Cells(1).Value = rdr("Regnr").ToString
                    Me.DataGridView1.Rows(i).Cells(2).Value = rdr("Datum").ToString
                    Me.DataGridView1.Rows(i).Cells(3).Value = rdr("BokTime").ToString
                    Me.DataGridView1.Rows(i).Cells(4).Value = rdr("Mek").ToString
                    Me.DataGridView1.Rows(i).Cells(5).Value = rdr("System").ToString
                    Me.DataGridView1.Rows(i).Cells(6).Value = rdr("Fplock").ToString

                    If Me.DataGridView1.Rows(i).Cells(6).Value = "X" Then
                        Me.DataGridView1.Rows(i).Cells(6).Value = "LDC"
                        With Me.DataGridView1.Rows(i).Cells(6).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With
                    End If

                    If Me.DataGridView1.Rows(i).Cells(6).Value = "-" Then
                        Me.DataGridView1.Rows(i).Cells(6).Value = "Inga delar"
                        With Me.DataGridView1.Rows(i).Cells(6).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With
                    End If

                    If Me.DataGridView1.Rows(i).Cells(6).Value = "V" Then
                        Me.DataGridView1.Rows(i).Cells(6).Value = "Ok utfört"
                        With Me.DataGridView1.Rows(i).Cells(6).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With
                    End If

                    If Me.DataGridView1.Rows(i).Cells(6).Value = "0" Then
                        Me.DataGridView1.Rows(i).Cells(6).Value = "Ej utfört"
                        With Me.DataGridView1.Rows(i).Cells(6).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.LightCoral

                        End With
                    End If

                    If Me.DataGridView1.Rows(i).Cells(6).Value = "Plockat" Then
                        Me.DataGridView1.Rows(i).Cells(6).Value = "Förplockat"
                        With Me.DataGridView1.Rows(i).Cells(6).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With
                    End If

                    If Me.DataGridView1.Rows(i).Cells(6).Value = "E" Then
                        Me.DataGridView1.Rows(i).Cells(6).Value = "Beställ delar"
                    End If

                    If Me.DataGridView1.Rows(i).Cells(6).Value = "B" Then
                        Me.DataGridView1.Rows(i).Cells(6).Value = "Beställt"
                    End If

                    Me.DataGridView1.Rows(i).Cells(8).Value = rdr("Start").ToString
                    If Me.DataGridView1.Rows(i).Cells(8).Value = "True" Then
                        Me.DataGridView1.Rows(i).Cells(8).Value = "Ja"
                    Else
                        Me.DataGridView1.Rows(i).Cells(8).Value = "Nej"
                    End If

                    Me.DataGridView1.Rows(i).Cells(7).Value = rdr("Mott").ToString
                    If Me.DataGridView1.Rows(i).Cells(7).Value = "True" Then
                        Me.DataGridView1.Rows(i).Cells(7).Value = "Ja"
                        With Me.DataGridView1.Rows(i).Cells(7).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With
                    Else
                        Me.DataGridView1.Rows(i).Cells(7).Value = ""
                    End If
                    Me.DataGridView1.Rows(i).Cells(8).Value = rdr("Start").ToString
                    If Me.DataGridView1.Rows(i).Cells(8).Value = "True" Then
                        Me.DataGridView1.Rows(i).Cells(8).Value = "Ja"

                        With Me.DataGridView1.Rows(i).Cells(8).Style
                            .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With
                        Me.DataGridView1.Rows(i).Cells(8).ToolTipText = "Arbete är påbörjat"

                    Else
                        Me.DataGridView1.Rows(i).Cells(8).Value = ""
                    End If

                    Me.DataGridView1.Rows(i).Cells(9).Value = rdr("Status").ToString
                    If Len(Me.DataGridView1.Rows(i).Cells(9).Value) > 1 Then


                        With Me.DataGridView1.Rows(i).Cells(9).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With

                    End If

                    Me.DataGridView1.Rows(i).Cells(10).Value = rdr("Avb").ToString
                    If Me.DataGridView1.Rows(i).Cells(10).Value = "True" Then
                        Me.DataGridView1.Rows(i).Cells(10).Value = "Ja"
                        With Me.DataGridView1.Rows(i).Cells(10).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.Yellow

                        End With
                    Else
                        Me.DataGridView1.Rows(i).Cells(10).Value = ""

                    End If

                    Me.DataGridView1.Rows(i).Cells(11).Value = rdr("Klar").ToString
                    If Me.DataGridView1.Rows(i).Cells(11).Value = "False" Then
                        Me.DataGridView1.Rows(i).Cells(11).Value = ""

                        '  With Me.DataGridView1.Rows(i).Cells(11).Style
                        '.Font = New Font("Verdana", 10)
                        '.'ForeColor = Color.Black
                        '.BackColor = Color.Moccasin
                        'End With

                        Me.DataGridView1.Rows(i).Cells(11).ToolTipText = "Verkstad arbete är inte klar"
                    Else
                        Me.DataGridView1.Rows(i).Cells(11).Value = "Ja"
                        With Me.DataGridView1.Rows(i).Cells(11).Style
                            .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With
                        Me.DataGridView1.Rows(i).Cells(11).ToolTipText = "Verkstad arbete är klar"

                    End If

                    Me.DataGridView1.Rows(i).Cells(12).Value = rdr("Utl").ToString

                    If Len(Me.DataGridView1.Rows(i).Cells(12).Value) > 1 Then


                        With Me.DataGridView1.Rows(i).Cells(12).Style
                            ' .Font = New Font("Verdana", 10)
                            .ForeColor = Color.Black
                            .BackColor = Color.MediumSpringGreen

                        End With

                    End If

                    Me.DataGridView1.Rows(i).Cells(13).Value = rdr("Avd").ToString
                End With

            Next i



            rdr.Close()
            conn.Close()



        Catch ex As Exception
    
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
          

            Exit Sub
        End Try
    End Sub


Svara

Nyligen

  • 09:09 Vill du köpa medicinska tester?
  • 12:47 Vem beviljar assistansen – kommune
  • 14:17 Någon med erfarenhet av hemstädnin
  • 14:14 Bör man använda sig av en båtförme
  • 14:12 Finns det någon intressant hundblo
  • 14:25 Tips på verktyg för att skapa QR-k
  • 14:23 Tips på verktyg för att skapa QR-k
  • 20:52 Fungerer innskuddsbonuser egentlig

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 569 153
27 952
271 704
745
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies