Avatar billede graspman Nybegynder
11. oktober 2003 - 13:35 Der er 3 kommentarer og
1 løsning

slette indholdet i et datagrid?

Er der nogen der kort kan fortælle mig hvorledes man sletter indholdet i et datagrid (der er fuldt op manuelt).

Hilsen Grasp
Avatar billede repsak Nybegynder
11. oktober 2003 - 13:46 #1
dataset.Clear()
datagrid.DataSource = dataset.Tables[0].DefaultView;
datagrid.DataBind();
Avatar billede graspman Nybegynder
11. oktober 2003 - 14:50 #2
ok :)

Du ved vel ikke hvorledes man ændre navnene på sine kolonner, således de ikke får de navne som der er i databasen ?

Hilsen Grasp
Avatar billede repsak Nybegynder
11. oktober 2003 - 17:12 #3
jo der er flere måder, men jeg plejer at give dem aliases:
SELECT name AS navn FROM persons;
Avatar billede edl Nybegynder
07. marts 2004 - 23:03 #4
'Prøv denne her kan du også lave nye faver på celler osv.
     
Imports System.Data.OleDb
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public ConnStringMaster As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Master.mdb;Persist Security Info=False;Jet OLEDB:Database Password=1010101010"
    Public AntalLogRows As Int32
'***********************************************************************************
Dim strSQL As String = "select ID, USER_NAME, LOGIN_TIME, LOG_OUT_TIME from Log_Detail where LOG_OUT_TIME <> 'CURRENT'"
        Dim Connection As New OleDbConnection(ConnStringMaster)
        Dim DA As New OleDbDataAdapter(strSQL, Connection)
        Dim DS As New DataSet

        'DBGrid.DataSource = DS
        DA.Fill(DS, "Log_Detail")

        With DBGrid
            .BackColor = Color.White
            .BackgroundColor = Color.White
            .BorderStyle = BorderStyle.FixedSingle
            .CaptionBackColor = Color.White
            .CaptionFont = New Font("Tahoma", 10.0!, FontStyle.Bold)
            .CaptionForeColor = Color.MidnightBlue
            .CaptionText = "Ind og udlogninger foretaget i systemet"
            .Font = New Font("Tahoma", 8.0!)
            .ParentRowsVisible = False
            .ParentRowsBackColor = Color.WhiteSmoke
            .ParentRowsForeColor = Color.WhiteSmoke
            .ColumnHeadersVisible = True
            .FlatMode = True
            .Width = 650
        End With

        ' Put as much of the formatting as possible here.
        Dim DBGridStyle As New DataGridTableStyle
        With DBGridStyle
            .AlternatingBackColor = Color.Lavender
            .BackColor = Color.WhiteSmoke
            .ForeColor = Color.MidnightBlue
            .GridLineColor = Color.Gainsboro
            .GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
            .HeaderBackColor = Color.MidnightBlue
            .HeaderFont = New Font("Tahoma", 8.0!, FontStyle.Bold)
            .HeaderForeColor = Color.WhiteSmoke
            .LinkColor = Color.Teal
            .SelectionBackColor = Color.CadetBlue
            .SelectionForeColor = Color.WhiteSmoke
            ' Do not forget to set the MappingName property.
            ' Without this, the DataGridTableStyle properties
            ' and any associated DataGridColumnStyle objects
            ' will have no effect.
            .MappingName = "Log_Detail"
            .PreferredColumnWidth = 125
            .PreferredRowHeight = 25
            .RowHeadersVisible = False
        End With


        Dim DBGridStyle1 As New DataGridTextBoxColumn
        Dim DBGridStyle2 As New DataGridTextBoxColumn
        Dim DBGridStyle3 As New DataGridTextBoxColumn
        Dim DBGridStyle4 As New DataGridTextBoxColumn

        'Hide column 1 by setting its width to 0.
        With DBGridStyle1
            .MappingName = "ID"
            .Width = 0
        End With

        With DBGridStyle2
            .HeaderText = "Bruger navn"
            .MappingName = "USER_NAME"
            .Width = 200
            .TextBox.Enabled = False
        End With

        With DBGridStyle3
            .HeaderText = "Tid indlogning"
            .MappingName = "LOGIN_TIME"
            .Width = 200
            .Alignment = HorizontalAlignment.Center
            .TextBox.Enabled = False
        End With

        With DBGridStyle4
            .HeaderText = "Tid udlogning"
            .MappingName = "LOG_OUT_TIME"
            .Width = 200
            .Alignment = HorizontalAlignment.Center
            .TextBox.Enabled = False
        End With
        '
        With DBGridStyle.GridColumnStyles
            .Add(DBGridStyle2)
            .Add(DBGridStyle3)
            .Add(DBGridStyle4)
            .Add(DBGridStyle1)
        End With
        '
        ' Add the GridColumnStyles to the aGridTableStyle.
        DBGrid.TableStyles.Add(DBGridStyle)

        '
        ' Bind the DataGrid to the DataSet. Expand and navigate to first row.

        AntalLogRows = DS.Tables(0).Rows.Count

        If DS.Tables(0).Rows.Count > 0 Then
            With DBGrid
                .DataSource = DS.Tables(0)
                .Expand(-1)
                .NavigateTo(0, "Log_Detail")
            End With
        End If
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester