DataGridTableStyle thru code

R

rbutch

hey guys need a little guidance - even a reference or two.
took VB.NeT in school but, they never seem to teach real world scenarios.
anyway. learned Connecting Using SERVER EXPLORER and the wizzards for building Data Adapters and Configuring Datasets. all of which requires a hard coded connection string.
so, now im learning that - that's rarely the case if at all. and i need some references on setting up the grid tablestyles thru code.
now i am connecting to Oracle and i can take the grid default that I get, but, it would serve me and anyone else much better if i could do this properly.
here's the code ive tried to change the Datagrid1 table style,column aliases etc.
if any one knows of a good reference book for this, i'd appreciate that too. but i have a small library (wrox press, murach, microsoft, etc). so something isnt clicking here.
here's the code. and the variables are fed into this form on Load. it works fine. i'd just like to be able to manipulate the table-styles.
thanks for any help given
rik

Private Sub Balances_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim ds As New DataSet
lblTheDate.Text = balDate
Dim sql As String
the_bal = check_accum(Accum)
Try
sql = "SELECT empl_id,accum_id,balance_date,(start_bal/60)from accum_balance where empl_id = '" & empl & "' and accum_id in ('" & the_bal & "') and balance_date = to_date('" & balDate & "','mm/dd/yyyy')"
Dim oracon As New OracleConnection("Server=atserver;Uid='" & user & "';Pwd='" & pwd1 & "'")
oracon.Open()
ds.Clear()
ds.EnforceConstraints = False
Dim myCmd As New OracleCommand
myCmd.Connection = oracon
myCmd.CommandText = sql
myCmd.CommandType = CommandType.Text
Dim myDa As New OracleDataAdapter(myCmd)
myDa.Fill(ds, "accum_balance")
If ds.Tables.Count = 0 Then
MessageBox.Show("nothing found")
ElseIf ds.Tables.Count >= 1 Then
DataGrid1.DataSource = ds.Tables(0)
Else
End If
oracon.Close()
DataGrid1.DataSource = ds 'binding the datasoure
DataGrid1.DataMember = "ACCUM_BALANCE"
Dim objStyle As New DataGridTableStyle
Dim objtext As New DataGridTextBoxColumn
objStyle.AlternatingBackColor = Color.Aqua

objtext.MappingName = "empl_id" ' column one
objtext.HeaderText = "Empl"
objStyle.GridColumnStyles.Add(objtext)

objtext = New DataGridTextBoxColumn 'going for column two
objtext.MappingName = "accum_id"
objtext.HeaderText = "TheBalance"
objStyle.GridColumnStyles.Add(objtext)

DataGrid1.TableStyles.Add(objStyle)

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try



End Sub

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
W

W.G. Ryan eMVP

Hi Rik:

First off, you can use the visual tools without hard coding connection
strings, as a matter of fact, I'd avoid doing that if at all possible.
Here's an example on how to do it with app.config or web.config - using the
specific exampel fo a connection string
http://www.knowdotnet.com/articles/attributes.html.

Here's another example http://www.knowdotnet.com/articles/cgrid.html of a
class that we wrote to handle changing tablestyles dynamically
http://www.knowdotnet.com/articles/cgrid.html . It can be a bit cumbersome
at first but by creating a reusable component, things are greatly
simplified.

HTH,

Bill
rik butcher said:
hey guys need a little guidance - even a reference or two.
took VB.NeT in school but, they never seem to teach real world scenarios.
anyway. learned Connecting Using SERVER EXPLORER and the wizzards for
building Data Adapters and Configuring Datasets. all of which requires a
hard coded connection string.
so, now im learning that - that's rarely the case if at all. and i need
some references on setting up the grid tablestyles thru code.
now i am connecting to Oracle and i can take the grid default that I get,
but, it would serve me and anyone else much better if i could do this
properly.
here's the code ive tried to change the Datagrid1 table style,column aliases etc.
if any one knows of a good reference book for this, i'd appreciate that
too. but i have a small library (wrox press, murach, microsoft, etc). so
something isnt clicking here.
here's the code. and the variables are fed into this form on Load. it
works fine. i'd just like to be able to manipulate the table-styles.
thanks for any help given
rik

Private Sub Balances_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
lblTheDate.Text = balDate
Dim sql As String
the_bal = check_accum(Accum)
Try
sql = "SELECT empl_id,accum_id,balance_date,(start_bal/60)from
accum_balance where empl_id = '" & empl & "' and accum_id in ('" & the_bal &
"') and balance_date = to_date('" & balDate & "','mm/dd/yyyy')"
Dim oracon As New OracleConnection("Server=atserver;Uid='" & user & "';Pwd='" & pwd1 & "'")
oracon.Open()
ds.Clear()
ds.EnforceConstraints = False
Dim myCmd As New OracleCommand
myCmd.Connection = oracon
myCmd.CommandText = sql
myCmd.CommandType = CommandType.Text
Dim myDa As New OracleDataAdapter(myCmd)
myDa.Fill(ds, "accum_balance")
If ds.Tables.Count = 0 Then
MessageBox.Show("nothing found")
ElseIf ds.Tables.Count >= 1 Then
DataGrid1.DataSource = ds.Tables(0)
Else
End If
oracon.Close()
DataGrid1.DataSource = ds 'binding the datasoure
DataGrid1.DataMember = "ACCUM_BALANCE"
Dim objStyle As New DataGridTableStyle
Dim objtext As New DataGridTextBoxColumn
objStyle.AlternatingBackColor = Color.Aqua

objtext.MappingName = "empl_id" ' column one
objtext.HeaderText = "Empl"
objStyle.GridColumnStyles.Add(objtext)

objtext = New DataGridTextBoxColumn 'going for column two
objtext.MappingName = "accum_id"
objtext.HeaderText = "TheBalance"
objStyle.GridColumnStyles.Add(objtext)

DataGrid1.TableStyles.Add(objStyle)

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try



End Sub

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top