|
Are you sure Mycroft? If sender is not a control, but is not null then the (Control) cast will give an InvalidCastException rather than return a null value.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm pretty sure, I'd have to test it but I seem to remember the tedious null checking I have to do every time I try to unbox from a UI/sender to a type in WPF.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I tried the code but when a click the button, it
displays an error that Index and length must
refer to a location within the string. Parameter
name: length
|
|
|
|
|
We can't see your screen, access your hard-drive, or read your mind.
Edit your question to post the relevant code and the exact error message, and to indicate the line in the code which produces the error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Without your code, we can't help: but that kind of error normally comes from an SQL Substring function - so start by looking at your queries and stored procedures, and the data you are passing to them.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I put an xml file with a structure like this
<list>
<person>
<name>Micky Mouse</name>
<phone>
<phone1>1111111</phone1>
<phone2>2222222</phone2>
</phone>
</person>
<person>
<name>Donald Duck</name>
<phone>
<phone1>3333333</phone1>
</phone>
</person>
<person>
<name>Pluto</name>
<phone>
</phone>
</person>
<person>
<name>Goofy</name>
<phone>
<phone1>5555555</phone1>
<phone2>6666666</phone2>
<phone3>7777777</phone3>
</phone>
</person>
.....
.....
.....
</list>
into a dataset and then I try to load the dataset into a list. The problem is there are 2 root tables (person and phone) in the main table (list) and I am not sure how to loop through the dataset to fill my list (List<Person> ListP = new List<Person>())
so that the the content of each would match the correct parts.
Example
ListP[0] would contain Micky Mouse, 1111111, 2222222,
ListP[1] would contain Donald Duck 333333
ListP[2] would contain Pluto
ListP[3] would contain Goofy 5555555, 6666666, 7777777
… ect
Thanks for any help
modified 18-Dec-14 4:31am.
|
|
|
|
|
According to the input you don't have two root tables. Phone is a nested table of person. Your Person object should look like this.
class Person
{
String Name;
List<String> Phone;
}
If you can influence how the list is generated, you should probably get the naming of the phone tags changed into something like this:
<phones>
<phone>11111</phone>
<phone>22222</phone>
</phones>
That would make parsing the list easier, as you wouldn't have all these differently names tags.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
I don't know why I wrote "root" tables. I meant 2 tables (person and phone) and that is what I don't know how to loop through properly and put there content into my list (List<person> ListP = new List<person>()).
I will try that change you wrote.
|
|
|
|
|
To add to what Freak30 has said I would also have a look at this
XML Serialization and Deserialization: Part-1[^]
It will save you half the work on firstly importing it to a dataset and then to a list.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
In WPF I have 3 calls to the database and a process that requires the results of these 3 call to complete. Currently I chain the calls and then call the processing method.
If I used an array of 3 tasks and initiating the processing method after Task.AwaitAll, would this achieve the same result as the chaining.
I know I can test this but I'm still reading and trying to relate this to actual issues.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It depends, but since you haven't shown your code that sets up the Tasks, it's pretty much just a guess at what you're really doing.
But, if none of the Tasks are waiting on each other, then all the Tasks will execute separately and at the same time. Task.WaitAll() will wait for all of the Tasks to complete.
|
|
|
|
|
I did not have any code to show as I was still reading the docs, just trying to relate to an actual issue I have.
Dave Kreskowiak wrote: Task.WaitAll() will wait for all of the Tasks to complete So I tried this with asynch Silverlight calls to the wcf
It had a number of issues around INotifyPropertyChanged which was used in the called process so I need to do some more reading and work out the best way to implement it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I use it in an a lot of places in my database access...
The only thing is important that the 3 calls must have to be unrelated...
Otherwise it can be a very good way to improve performance...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: The only thing is important that the 3 calls must have to be unrelated Define unrelated, I would expect to use it where I have multiple selects when opening a view but would never use it when inserting/updating multiple records.
The selects would be on different but related tables I don't see this as a problem.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
In this context unrelated means that the outcome of one call does not effect the others...Which you say no...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
As I understand your post, currently you have 3 awaitable calls which you are chaining to execute one after another in your processing method and awaiting the processing method.
If my understanding is correct, I think the array of tasks with Task.WaitAll() should perform better.
And I think you meant Task.WaitAll().
Your time will come, if you let it be right.
|
|
|
|
|
You are correct, for some reason I have Await stuck in my head and that is what comes out the fingers - then I get annoyed with intellisense when it does not know what I want.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
For .NET 4.5 with async / await , using await Task.WhenAll(tasks); is better than using Task.WaitAll(tasks); . The former releases the current thread until the tasks are complete; the latter blocks the current thread waiting for the tasks to complete.
Task.WhenAll method[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Did not know that, thanks!
Your time will come, if you let it be right.
|
|
|
|
|
Hi,
some month ago, google have deprecate the 2nd version of "Google Calendar API", and my windows application stop to work.
Now I start to rewrote the code, but i discover a surprise, to add, delete, modify, list the appointments in 10 different google calendar, i need to do the authentication with OAuth2.0. And now appear the problem, I have stressed google to find an example of code, but every code was write for webapplication(asp.net) and not for a standalone windows application.
Somebody can help me to find a solution/example to integrate in my code????
|
|
|
|
|
Hi,
I need to add rows in datagridview in Visual Studio in design mode (not programmatically), how can I add rows this way? I was able to add columns but not rows?
|
|
|
|
|
You don't.
Adding data to the DataSource, usually a DataTable, is a run-time thing.
|
|
|
|
|
Thanks for clearing that up.
Do you know why they would allow you to add columns via design mode?
|
|
|
|
|
|
Thank you.
I cannot get anything to work to add the code at runtime, besides having a button click add row by row (which I do not want and cannot use) so somehow I've done something in the beginning to break it in trying to figure this out, and now that I've asked for help and gotten working examples, it is thwarting my ability to get it to work properly.
Even the code from the msdn site isn't working and my data grid is indeed called dataGridView1?
[code]
private void Form1_Load(object sender, EventArgs e)
{
InitializeDataGridView();
}
private void InitializeDataGridView()
{
// Create an unbound DataGridView by declaring a column count.
dataGridView1.ColumnCount = 4;
dataGridView1.ColumnHeadersVisible = true;
// Set the column header style.
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.BackColor = Color.Beige;
columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// Set the column header names.
dataGridView1.Columns[0].Name = "Recipe";
dataGridView1.Columns[1].Name = "Category";
dataGridView1.Columns[2].Name = "Main Ingredients";
dataGridView1.Columns[3].Name = "Rating";
// Populate the rows.
string[] row1 = new string[] { "Meatloaf", "Main Dish", "ground beef",
"**" };
string[] row2 = new string[] { "Key Lime Pie", "Dessert",
"lime juice, evaporated milk", "****" };
string[] row3 = new string[] { "Orange-Salsa Pork Chops", "Main Dish",
"pork chops, salsa, orange juice", "****" };
string[] row4 = new string[] { "Black Bean and Rice Salad", "Salad",
"black beans, brown rice", "****" };
string[] row5 = new string[] { "Chocolate Cheesecake", "Dessert",
"cream cheese", "***" };
string[] row6 = new string[] { "Black Bean Dip", "Appetizer",
"black beans, sour cream", "***" };
object[] rows = new object[] { row1, row2, row3, row4, row5, row6 };
foreach (string[] rowArray in rows)
{
dataGridView1.Rows.Add(rowArray);
}
}
[/code]
|
|
|
|