Click here to Skip to main content
15,905,068 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone

I used setmethod named setMyDataGridStyleProperties(EMdgv // my datagrid name//)setmethod has features of tablestyle and tablecolumn. I am accessing it in fillgrid() method. But it is giving error.
Call setMyDataGridTableStyleProperties(EMdgv)
//I am getting error in above step at EMdgv as value of type systems.windows.forms.DataGridView cannot be converted to system.windows.forms.DataGrid//


Kindly please let me know how to correct this error.

Here by i am giving both codes of Fill grid() & setMyDataGridStyleProperties(ByRef dg As datagrid)


Sub FillGrid()


Try



s = "select expenseID,expensename from expensemaster"


ds = SqlHelper.ExecuteQueryReturnDataset(s)


EMdgv.DataSource = ds.Tables(0)


Call setMyDataGridTableStyleProperties(EMdgv)
' I am getting error in above step at EMdgv as value of type systems.windows.forms.DataGridView cannot be converted to system.windows.forms.DataGrid'
EMdgv.Visible = True
EMdgv.ReadOnly = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub setMyDataGridTableStyleProperties(ByRef dg As DataGrid)
Dim dgstyle As New DataGridTableStyle()
Dim colstyle1 As New DataGridTextBoxColumn()
Dim colstyle2 As New DataGridTextBoxColumn()
With dgstyle
.AlternatingBackColor = Color.LightCoral
.BackColor = Color.LawnGreen
.ForeColor = Color.LightGray
.HeaderBackColor = Color.LightGray
.HeaderFont = New Font("Courier", 10.0!, FontStyle.Bold)
.HeaderForeColor = Color.LawnGreen
.LinkColor = Color.Teal
.MappingName = "expensemaster"
.SelectionBackColor = Color.LawnGreen
.SelectionForeColor = Color.LightGray
End With
With colstyle1
.HeaderText = "expenseID"
.MappingName = "Expense-ID"
.Width = 50
End With
With colstyle2
.HeaderText = "expensename"
.MappingName = "ExpenseName"
.Width = 140
End With
dgstyle.GridColumnStyles.AddRange _
(New DataGridColumnStyle() _
{colstyle1, colstyle2})
dg.TableStyles.Add(dgstyle)


End Sub
The 2nd sub method is setMyDataGridTableStyleProperties i am not understanding where to call to this to execute correctly

Looking forward for good help to solve my error

Thanx a lot
Posted

1 solution

I have no idea what you're trying to do with this, but this code only works with the old-style DataGrid control. You're trying to use the newer DataGridView with it, which won't work.

You'll have to rewrite this code to set the correct properties and styles on a DataGridView, or remove the DataGridView control you're using and go back to the old DataGrid control, which I recommend you do NOT do.
 
Share this answer
 
Comments
parchuri08 6-Nov-10 3:49am    
Thankyou for illustrating clearly . I understood that i am accesing two different things like datagrid and datagridview.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900