Results 1 to 2 of 2

Thread: Help setting datagrid properties

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2004
    Location
    New York City
    Posts
    69

    Help setting datagrid properties

    Hi all, I hope you guys can help me with this issue.
    i am creating a windows form and cannot set the properties for the colums.
    e.g changing the colum name and alternating background color. I have attached some of the code to see if anyone may help me or tell me what I am doing wrong. The form doesnt give me any error but it does not change the property either.

    Thanks in advance.

    Private Function mainconn()
    Dim checkcon As String
    objconnection.Open()
    a.SelectCommand = New OleDbCommand
    a.SelectCommand.Connection = objconnection
    'Selects the ID, Name, LastName etc fields on the table
    a.SelectCommand.CommandText = _
    " SELECT * from financial order by timein"
    a.SelectCommand.CommandType = CommandType.Text
    a.SelectCommand.ExecuteNonQuery()
    a.Fill(ds, "financial")
    objconnection.Close()
    a = Nothing
    objconnection = Nothing

    'grid
    DataGrid1.DataSource = ds
    DataGrid1.DataMember = "financial"


    DataGrid1.ColumnHeadersVisible = True
    'declaring objects
    Dim datagridtablestyle As New DataGridTableStyle
    Dim columnstyle As New DataGridTextBoxColumn
    'alternating color
    datagridtablestyle.AlternatingBackColor = Color.WhiteSmoke
    datagridtablestyle.MappingName = "Financial"

    columnstyle.MappingName = "ID"
    columnstyle.HeaderText = "Test ID"
    'same settings for the rest of the fields
    datagridtablestyle.GridColumnStyles.Add(columnstyle)
    DataGrid1.TableStyles.Add(datagridtablestyle)

    End Function

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Not very sure why but DG may need to be refreshed and get replaced in the Form collection's object .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width