daniel2milan Posted September 19, 2005 Posted September 19, 2005 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 Quote
daniel2milan Posted September 19, 2005 Author Posted September 19, 2005 do any 1 could assist me?? thx Quote
Goksly Posted September 19, 2005 Posted September 19, 2005 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 :) Quote
daniel2milan Posted September 20, 2005 Author Posted September 20, 2005 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? Quote
daniel2milan Posted September 20, 2005 Author Posted September 20, 2005 pheww fortunately i've solved the problem on the programmaticaly connection you should add MyOleDataAdapter.Fill(MyDataSet,"usher") then its work Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.