I'm trying to convert my VB code to C# in way that I could plot a data values in datagridview on chart ( or any easy way can do that using C#)
For example I created a code in fluid dynamic which calculate the water head diffusion from high potential to low potential with respect to X (distance) using some linear analytical solution
As you can see my calculation was sent to the table under (hx column), then I plotted the hx data vs x values as it is shown in the figure:
This is the code which specifies the datagrid values
Public Sub New()
InitializeComponent()
Me.KeyPreview = True
' Dim dt As New DataTable()
' dt.Columns.Add("X_Value")
' dt.Columns.Add("Y_Value")
uncGrid.DataSource = dt.DefaultView
Chart1.DataSource = dt
Chart1.Series(0).XValueMember = "Destance_at_Position(m)"
Chart1.Series(0).YValueMembers = "hx(m)"
Chart1.DataBind()
Me.Chart1.Select()
End Sub
This is the lines where I bind the data with chart
Private Sub uncGrid_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles uncGrid.CellValidating
If Me.Visible And Not uncGrid.DataSource Is Nothing Then
Chart1.DataBind()
End If
End Sub
Finally this is for chart drawling and properties
Private Sub Chart1_PostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs) Handles Chart1.PostPaint
Dim o As Object = e.ChartElement
If o.[GetType]().Equals(GetType(System.Windows.Forms.DataVisualization.Charting.Series)) Then
Dim xVal As Single = CSng(e.ChartGraphics.GetPositionFromAxis(e.Chart.ChartAreas(0).Name, System.Windows.Forms.DataVisualization.Charting.AxisName.X, _x))
Dim pt As PointF = e.ChartGraphics.GetAbsolutePoint(New PointF(xVal, 0))
e.ChartGraphics.Graphics.DrawLine(Pens.Red, pt, New PointF(pt.X, e.Chart.ClientSize.Height))
If _x - 1 > -1 AndAlso _x - 1 < uncGrid.Rows.Count Then
_dontDo = True
uncGrid.ClearSelection()
Me.uncGrid.Rows(_x - 1).Selected = True
_dontDo = False
End If
End If
End Sub
End Class
Here is the C# part where it shows many error and said undefined function
public Unconfined_Aquifer()
{
Load += Unconfined_Aquifer_Load;
InitializeComponent();
this.KeyPreview = true;
uncGrid.DataSource = dt.DefaultView;
Chart1.DataSource = dt;
Chart1.Series(0).XValueMember = "Destance_at_Position(m)";
Chart1.Series(0).YValueMembers = "hx(m)";
Chart1.DataBind();
this.Chart1.Select();
}