Few days ago start programing in SilverLight and have a bit of a problem with saving data in local a variable from database by using wcf&linq. The connection and data result are working.
public void load(){
ServiceReference.ServiceClient serv=new ServiceReference.ServiceClient();
serv.GetAssetListCompleted+=new EventHandler<ServiceReference1.GetAssetListCompletedArgs>(serv_GetAssetListCompleted);
serv.GetAssetListAsync();
}
void serv_GetAssetList(object sender, ServiceReference.GetAssetListCompletedEventArgs e)
{
datagrid1.ItemsSource=e.Result;
}
This code is working and my datagrid1 is filling up with element.(AutoGenerateColumns="True") in Xaml-code. But I want to save this datagrid into a list or something else. Because I want to use these information like local variable.
Tried so many code like:
void serv_GetAssetList(object sender, ServiceReference.GetAssetListCompletedEventArgs e)
{
var result_list=e.Result.toList();
}
Or
void serv_GetAssetList(object sender, ServiceReference.GetAssetListCompletedEventArgs e)
{
string[] temp=new string[e.Result.Count];
for (int i=0;i<e.Result.Count;i++)
temp[i]=e.Result[i].Id;
}
But none work. All of them show an empty variable.
Try this:
void serv_GetAssetList(object sender, ServiceReference.GetAssetListCompletedEventArgs e)
{
MessageBox.show(e.result.count);
}
Related
I have the following Problem, i created a C# User Control with a couple of Input fields.
I implemented 2 Main functions ( Set_Data and Read_Data).
Set Data Reads some Data from a Class and Displays it at the User_Control.
Read_Data: Reads the Input value and stores it inside the same Class.
These functions are tested and work properly.
But if i try to use the same User Control to store the Data into another Instance of the same class the Information in the first Class stores the values of the second one too.
Maybe im just doing something wrong.
private Data_Class DataClass1 = new Data_Class();
private Data_Class DataClass2 = new Data_Class();
private void btn_page1_Click(object sender, EventArgs e)
{
page = "page1";
UserControl1.set_Data(DataClass1);
UserControl1.BringToFront();
}
private void btn_page2_Click(object sender, EventArgs e)
{
page = "page2";
UserControl1.set_Data(DataClass2);
UserControl1.BringToFront();
}
private void check_pagechange_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (page != last_page)
{
if (last_page == "page1")
{
DataClass1 = UserControl1.read_Data();
}
if (last_page == "page2")
{
DataClass2 = UserControl1.read_Data();
}
last_page = page;
}
}
As it can be seen i use a Backgroundworker which reads the Data from the Usercontrol when there is a Pagechange.
i am trying to upload a csv file data to DB.
the process is like :
i am extracting csv file data to DataTable.
validating DataTable fields .
if all good , loading them into DB on button click.
i am generating invTable at below validation method by passing saved csv file path on validate button click.
protected void ValidateData_Click(object sender, EventArgs e)
{
ValidateCsv();
}
private void ValidateCsv(string fileContent)
{
DataTable getCSVData;
getCSVData = GetData(fileContent);
invTable= Validate(getCSVData);
}
if am loading it on BulkUpload_Click, invTable is null.
ideally it should have data , as assinged in ValidateCsv method.
protected void BulkUpload_Click(object sender, EventArgs e)
{
MatchedRecords(invTable);
}
any idea how to maintain invTable data across postback?
Change your ValidateCsv to a function.
private DataTable ValidateCsv(string fileContent)
{
DataTable getCSVData;
getCSVData = GetData(fileContent);
invTable = Validate(getCSVData);
return invTable;
}
Then on your MatchedRecords, modify it to accept a DataTable parameter.
private void MatchedRecords(DataTable invTable) {
}
Then on your BulkUpload_Click event, reference to the ValidateCsv, now a function that returns the value of your DataTable to the MatchedRecords void.
protected void BulkUpload_Click(object sender, EventArgs e)
{
MatchedRecords(ValidateCsv('enter how you get the fileContent here...'));
}
Or
protected void BulkUpload_Click(object sender, EventArgs e)
{
DataTable valueTable = ValidateCsv('enter how you get the fileContent here...');
MatchedRecords(valueTable);
}
I know, i know there are lots and lots of questions asking on here about this error, each with their own response, but its easier to work off a response regarding your own code rather than someone else's
I have been working on this program for some time for a college assignment, and as soon as i started putting in the class to calculate the totals of things it now crashes,
I don't know where to look so i'll post my main code
enter code here
namespace Till
public partial class MainWindow : Window
{
Calculator calc = new Calculator();
public MainWindow()
{
InitializeComponent();
}
public bool User;
public bool tillopen = false;
private void button_Click(object sender, RoutedEventArgs e)
{
//button clone thingy
Button btn = (Button)sender;
label.Content = label.Content + btn.Content.ToString();
Console.Beep(); // makes the buttons beep
}
private void clear_Click(object sender, RoutedEventArgs e)
{
// Clear
label.Content = "";
}
private void Button_Submit_Click(object sender, RoutedEventArgs e)
{
// submit
listView.Items.Add(label.Content);
label.Content = "";
calc.setSoldItems(Convert.ToInt32(label.Content)); /// it breaks on this line///
}
private void button13_Click(object sender, RoutedEventArgs e)
{
//void sale
label.Content = "";
listView.Items.Clear();
}
private void button15_Click(object sender, RoutedEventArgs e)
{
//pound
label.Content = "1.00";
}
private void button12_Click(object sender, RoutedEventArgs e)
{
//till open close
tillopen = true;
}
private void button16_Click(object sender, RoutedEventArgs e)
{
Login m = new Login();
m.Show();
this.Close();
}
private void button14_Click(object sender, RoutedEventArgs e)
{
label.Content = "2.00"; // 2 pound
}
private void button17_Click(object sender, RoutedEventArgs e)
{
label.Content = calc.finish();
}
}
I have tried to re-create the error in another WPF (converting a to an int32) and it works fine, i know this is an issue with my code itself, i have tried using other machine and using different versions of visual studio itself, so we came to the assumption its this code itself and not a broken dll file
So before I sit down with my Teacher and spend all day going though my code step by step im asking around for help in order to save both of our time, This assignment is due in in 3 weeks, and it decides to break on me now.
thankies
To replicate this error, i press a number button on my Windows form, them hit the submit button i created (which starts the conversion) If a copy of my class which handles all of this is needed im happy to post it
In the method button_click, you have assigned value as
label.Content = label.Content + btn.Content.ToString();
which is a string value to the label and the values are concatenated instead of add.
and when you are reading it, you are converting it in Int32. which will give exception as it will not contain any integer value to it.
You can add the value like this:
label.Content = (Convert.ToInt32(label.Content) + Convert.ToInt32(btn.Content)).ToString();
and check before converting if the label has blank values in it, if it has do not convert them, and only convert the value if it has some values it will not give any error. Also do not assign any values other that numerical digits.
You are calculating:
Convert.ToInt32(label.Content)
but on the line before you set:
label.Content = "";
so this means you are calculating
Convert.ToInt32("")
which gives you a FormatException.
Perhaps you should use the value of label.Content before you overwrite it?
I'm trying to split send data into different display boxes and I'm having hard time..
I'm using MS Visual Studio 2013 and Networks API library.
Server-side program code is following:
private void button2_Click(object sender, EventArgs e)
{
server.BroadCast(textBox2.Text);
}
Whatever is in textBox2 is BroadCasted to client-side program (to everyone who is connected)
private void button1_Click(object sender, EventArgs e)
{
server.SendTo((string)listBox1.SelectedItem, textBox2.Text);
}
Private message to chosen user.. but here is my problem:
In Client-side program anything what is received will be displayed in one same box and I want to split it; private messages into own box and broadcasted messages to its own..
currently I have following code:
void Chatprojekti_OnDataReceived(object Sender, ClientReceivedArguments R)
{
ChangeTextBox(R.ReceivedData);
}
private void ChangeTextBox(string txt) // Chatlog update
{
if(textBox1.InvokeRequired)
{
Invoke(new UpdateText(ChangeTextBox), new object[] { txt });
}
else
{
textBox1.Text += txt + "\r\n";
}
}
I don't have any ideas how to do it, but hopefully some of you can give me tip how to do it, Thanks! :)
I have a richtextbox and i want to delete not cut the selected when the user presses a button.
I have used
private void button1_Click(object sender, EventArgs e)
{
SendKeys.Send("DELETE");
}
This works but i want to know another way to do it.
I have tried
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectedText.Replace(richTextBox1.SelectedText, "");
}
This doesn't perform any action.
Pls what can i do?
Just do this:
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectedText = "";
}
Your code doesn't work because the string is immutable, you can't change the richTextBox1.SelectedText that way. All the methods (Replace, Insert, ...) performed on a string will create a new string. This new string will be used to initialize your string variable if you need.
The following line of code works for me:
SendKeys.Send("{DELETE}");
Click Link to visit the Official documentation on SendKeys methods.