Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 6 > C# 6 General Discussion
|
C# 6 General Discussion Discussions about the C# 6 language and tools not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 6 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2016, 10:04 PM
Registered User
 
Join Date: Sep 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

code
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)
{
break;
}
indx += 1;
}
(Statistic)StatisticDataGrid.Items(indx).Yr2016 = intOld + intNew;
try // Code in question
{
db.SubmitChanges();
MessageBox.Show("All DataGrids have been saved to the database.");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
/code
 
Old July 2nd, 2016, 10:46 AM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Using collections and arrays, with C# you need square brackets:
Code:
.Items[index]
If you installed extensions to Visual Studio, you can uninstall them from Tools | Extensions and Updates
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
 
Old July 2nd, 2016, 09:39 PM
Registered User
 
Join Date: Sep 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

BobE





Similar Threads
Thread Thread Starter Forum Replies Last Post
Do u know PHP Programming is Most Used Programming Language annaawills Beginning PHP 5 March 8th, 2010 09:48 AM
device DLL programming in client side programming hendyhanusin ASP.NET 1.0 and 1.1 Professional 2 February 19th, 2009 12:01 PM
device DLL programming in client side programming hendyhanusin ASP.NET 1.0 and 1.1 Basics 0 March 21st, 2007 08:05 AM
device DLL programming in client side programming hendyhanusin ASP.NET 2.0 Professional 1 March 21st, 2007 08:04 AM
Qt programming, bugs in first programming sateeshgalla BOOK Beginning Linux Programming, 3rd Edition 0 October 14th, 2005 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.