Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 6 > C# 6 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 12th, 2016, 10:04 PM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old July 2nd, 2016, 10:46 AM
Wrox Author
Points: 1,151, Level: 13
Points: 1,151, Level: 13 Points: 1,151, Level: 13 Points: 1,151, Level: 13
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Sep 2010
Location: Austria
Posts: 171
Thanks: 2
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
Reply With Quote
  #3 (permalink)  
Old July 2nd, 2016, 09:39 PM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08:48 AM
device DLL programming in client side programming hendyhanusin ASP.NET 1.0 and 1.1 Professional 2 February 19th, 2009 11:01 AM
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



All times are GMT -4. The time now is 06:01 AM.


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