VB.NET - Still cant code behind to add data columns up to show totals on bottom of Xaml/winform

Asked By David on 25-Feb-13 02:58 PM
 Hi all still not finished my prog and have had 58 views and no replies so it looks a hard task
I was given code but none of it works
 public double Total
{
get
{
return this.ColA + this.ColB + this.ColC;
}
set
{

}
}

The above code says not allowed.
I have made an extra column in dataset then double clicked on it and it says enter code here to add columns up but I cant find out how
There is No Get/Set and it says double not allowed any ideas please

David


Robbe Morris replied to David on 25-Feb-13 05:40 PM
You didn't get an answer because your post doesn't make any sense.

public double Total
{
  get
  {
    return this.ColA + this.ColB + this.ColC;
  }
  set
  {

  }
}


The above code says not allowed.

"What" says it is not allowed?  Assuming that ColA, ColB, and ColC are all numeric oriented data types that can fit into a "double" data type and are properties of the class that holds Total, this is perfectly fine code.  There is something about your code and design you are not telling us.  You take about a property on a class and then start referring to columns in a DataSet.  So, I'm at a bit of a loss as to what it is your code is suppose to do and how.
David replied to Robbe Morris on 26-Feb-13 03:26 AM
 Thanks for your reply Robbe
 I am sorry my understanding of code behind is linited so I will try and explain again what I am trying to do
I want a total showing at the bottom of my input Xaml/form in a textbox showing the total sum of 18 bound textboxes on that form. I have made an extra column on the dataset called totalscore, and then when i double clicked on it up came the
following code.

Partial Class CoursesPlayedDataSetPartial Class COURSES_PLAYEDDataTable

Private Sub COURSES_PLAYEDDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanging

If (e.Column.ColumnName = Me.TotalScoreColumn.ColumnName) Then

'Add user code here

End If

End Sub

End Class

End


Class


I was hoping to bind the sum to the form giving the sum total in a bound Textbox.Have I choseb the wrong typs of class? When I tried to add the code Public double total etc it said not supported
Also the "{" are not in any of my codes I think the code is vb.net

Thanks David
Robbe Morris replied to David on 26-Feb-13 08:35 AM
Your data class has to implement the INotifyPropertyChanged interface.  And, in each of your properties to be totalled, you have to call PropertyChanged("Total") to trigger the event that updates the user interface.

I do not believe you can accomplish this with a DataSet because it has no underlying logic or event mechanism to manage "total" or calculated columns.  You'd want to use an ObservableCollection<T> when binding a collection in XAML.
David replied to Robbe Morris on 26-Feb-13 02:43 PM
 Thanks Robbe
 I know very little about the code  I need to do what you suggest can you point me in the right direction please
  "ObservableCollection<T> when binding a collection in XAML"
 In the code generated by clicking on extra row/class there are in common code loads of my columns
 H1SCcolumn,H2SCcolumn what are these for ? and could they be used in the calling of a sum total
 Thanks David
Robbe Morris replied to David on 26-Feb-13 03:51 PM

var list = new ObservableCollection<MyCustomClass>();

foreach(var row in dataSet.Tables[0].Rows)
{
    var item = new MyCustomClass();

    item.ColumnA = row["SomeColumnName"];
   
   list.Add(item);
}

You'd bind the "list" to your XAML.  We have all sorts of data binding articles for XAML here:

http://www.eggheadcafe.com/articlelist.aspx?topicid=56
David replied to Robbe Morris on 26-Feb-13 05:02 PM
 Thanks Robbie I will try Tues to covert to .Net

 David
David replied to Robbe Morris on 27-Feb-13 04:46 PM
 Hi Robbe
 I have run your code through a convertor and it comes out like this in VB.NET

Dim


list = New ObservableCollection(Of MyCustomClass)(T)

For Each row As var In DataSet.Tables(0).Rows

Dim item = New MyCustomClass(T)

item.ColumnA = row(

"columnH1SC")

list.Add(item)

Next


ObservableCollection(Of MyCustomClass)(T) and var are not defined 
should this code go in Xaml.vb and if so what as public/partial class etc

Thanks David
 
David replied to David on 28-Feb-13 04:49 PM
 Hi Robbe
 Sorry to be a pain where should I be trying to code the ObservableCollection(Of MyCustomClass)(T
 should it be in xaml vb

Thanks

David