C# 6 General DiscussionDiscussions 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
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
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.