p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   C# 6 General Discussion (http://p2p.wrox.com/c-6-general-discussion-806/)
-   -   Help with a C# programming statement (http://p2p.wrox.com/c-6-general-discussion/99032-help-c-programming-statement.html)

BobE June 12th, 2016 11:04 PM

Help with a C# programming statement
I just recently purchased 3 of your books: 1) Professional Visual Studio 2015; 2) Beginning C# 6 Programming with Visual Studio 2015; and an e-book 3) Professional C# 6 and .NET Core 1.0.

I’m starting to learn and use the C# programming language. I changed a WPF Visual Basic project into a C# project in which a button-click event places the sum of two integers into a cell in column ‘Yr2016’ of an indexed row in a DataGrid. In the statement: (Statistic)StatisticDataGrid.Items(index). Yr2016 = intOld + intNew -- I get the message: “Non-invocable member ‘itemsControl.items’ cannot be used like a method.” Only the word .Items had the red squiggly line under it.

This following statement in Visual Basic worked real well --
CType(StatisticDataGrid.Items(index), Statistic).Yr2016 = intOld + intNew
What do I need to do in order to make the equivalent C# statement above work?

A second question that I have is; how can I delete from Visual Studio, templates that I down-loaded from Nu-get?

private void btnAddTo_Click(object sender, RoutedEventArgs e)
// Add the contents of the two textboxes
string strOld = Yr2016TextBox.Text;
if (string.IsNullOrEmpty((Yr2016TextBox.Text)))
strOld = "0";
string strNew = AddToTxtBx.Text;
int intOld = int.Parse(strOld);
int intNew = int.Parse(strNew);
Yr2016TextBox.Text = (intOld + intNew).ToString();
// Query the Statistics country column
int indx = 0;
string strRow = "";
decimal intRow = 0M;
strRow = CountryComboBox.Text;
var Contry = from cont in db.Statistics
select cont.Country;
// Get the 0-based index row number
foreach (var cont in Contry)
if (cont == strRow)
indx += 1;
(Statistic)StatisticDataGrid.Items(indx).Yr2016 = intOld + intNew;
try // Code in question
MessageBox.Show("All DataGrids have been saved to the database.");
catch (Exception ex)

ChristianNagel July 2nd, 2016 11:46 AM

Using collections and arrays, with C# you need square brackets:

If you installed extensions to Visual Studio, you can uninstall them from Tools | Extensions and Updates

BobE July 2nd, 2016 10:39 PM

Thank you for your reply, I enclosed “indx” with square brackets instead of parentheses as you said, but then had to add the parentheses around a larger portion of the statement. Then it worked fine, thanks again.


All times are GMT -4. The time now is 12:56 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.