Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i have this code in order to customize datagrid but the header text wont appear n only return blank datagrid can some 1 help me?? is there any incorrect syntax on my code??

 

    Public Function FillDataGrid(ByVal Sqlstring As String)


       Dim OleDbConn As OleDbConnection = New OleDbConnection(ConnString)
       OleDbConn.Open()

       Dim MyDataSet As DataSet = New DataSet

       Dim MyOleDataAdapter As OleDbDataAdapter = New OleDbDataAdapter
       MyOleDataAdapter.SelectCommand = New OleDbCommand(Sqlstring, OleDbConn)

       MyOleDataAdapter.Fill(MyDataSet)
       Dim tableStyle As New DataGridTableStyle
       DataGrid1.DataSource = MyDataSet

       tableStyle.MappingName = "usher"

       Dim column1 As New DataGridTextBoxColumn
       column1.MappingName = "userID"
       column1.HeaderText = "User Name"
       column1.Width = 30
       tableStyle.GridColumnStyles.Add(column1)

       'Me.DataGrid1.DataSource = MyDataSet.Tables(0).DefaultView
       Me.DataGrid1.TableStyles.Add(tableStyle)




       'For x As Integer = 0 To MyDataSet.Tables(0).Rows.Count - 1
       'ListBox1.Items.Add(MyDataSet.Tables(0).Rows(x).Item("Nama"))
       'Next

       'StatusBar1.Text = " " & MyDataSet.Tables(0).Rows.Count & " Rows."

       MyOleDataAdapter.Dispose()
       MyDataSet.Dispose()

       OleDbConn.Close()
       OleDbConn.Dispose()

       If Not OleDbConn Is Nothing Then
           OleDbConn.Close()
           OleDbConn.Dispose()
       End If


   End Function

Posted

Just as the columns have mapping names that need to match, so does the actual datatablestyle!

What I normally do, to make sure they match is, just before adding the table style (but after binding the datagrid) I will do:

tableStyle.MappingName = ((DataTable) dataGrid1.DataSource).TableName

 

Another method is to create the DataTable with a name:

Dim MyDataTable As DataTable = New DataTable ("usher")

 

(and then use the datatable as the datasource, rather than one of the datasets tables).

 

Im not great with vb so ive written the first in C# -> hope it points you in the right direction :)

Posted

thx for the reply but still won't work.

 

Public Function FillDataGrid(ByVal Sqlstring As String) is function with sql command input such as "select * from usher"

 

so the query has been add in

 

  Dim MyDataSet As DataSet = New DataSet

       Dim MyOleDataAdapter As OleDbDataAdapter = New OleDbDataAdapter
       MyOleDataAdapter.SelectCommand = New OleDbCommand(Sqlstring, OleDbConn)

       MyOleDataAdapter.Fill(MyDataSet)

 

 

The table occur when i add this command

 

me.datagrid1.recordsource = mydataset.tables(0)

 

but when i add some tablestyle on it the changes won't occur and still show the same table not the 1 i expected.

 

for more information i make the connection manually / programmatically, can tablestyle is implemented on those codings?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...