Reputation: 61
I'm building a little app in C# WPF and it contains a local SQL database. This is then shown on a Data grid on the main window. I'm having problems where when i click to edit a certain row in the data grid it backfires on converting the text in the textbox to the Int i'm passing from the main window.
Below is the main window method i'm using for when the user clicks to edit.
editStudent edit = new editStudent(stud.Id, stud.FirstName, stud.LastName, stud.Component1, stud.Component2, stud.Component3);
then on the editStudent.cs file i have this in the constructor to pre fill the textboxes and comboboxes with the data from mainWindow. Everything i try to run the app i says there is an exception on the cast in the constructor. I'm just wondering is there is another way to do it?
This is the constructor at the mo:
public editStudent(int matno, string firstname, string lastname, string combo1, string combo2, string combo3)
{
InitializeComponent();
matNoEditTbx.Text = matno;
firstEditTbx.Text = firstname;
lastEditTbx.Text = lastname;
com1ComboEdit.Text = combo1;
com2ComboEdit.Text = combo2;
com3ComboEdit.Text = combo3;
}
Visual studio has a problem with the first assigned textbox which is matNoEditTbx.Text.
Upvotes: 0
Views: 59
Reputation: 13
it's impossible to convert implicitly int to string
matNoEditTbx.Text = Convert.ToString(matno);
//or :
matNoEditTbx.Text = matno.ToString():
Upvotes: 0
Reputation: 401
You cannot assign an int to the Text of the TextBox. You should do:
matNoEditTbx.Text = matno.ToString():
Upvotes: 1