|
I have been familiarizing myself with this, but keep thinking that ... given the efficiency of .NET's hash-based data structures ... unless I had a huge SortedList<TKey, TValue> list, frequently accessed, with a large percentage of accesses matching the sort-order ... that I might as well use a hash-based solution.
On the "plus side," SortedList offers some nice facilities, like 'IndexOfValue, and it's easy to work-around having duplicate keys by using a custom IComparer<TKey> implementation.
Of course, if you choose to allow duplicate keys: changing the value associated with the key does not resort the list; to force a re-sort you have to remove the Key-Value pair, change the Value, and then, add the modified Key-Value pair back to the list.
Appreciate hearing from you about the strategic use of this data-structure.
thanks, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 5-May-18 14:54pm.
|
|
|
|
|
All my use seems to center around transporting "series data" from various sources into my "charting components"; mostly of the form SortedList<object,object>; i.e. <x,y>.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks, Gerry, I am interested in why you chose a SortedList for this task; I assume 'x,y' refers to a list of discrete 'Point (i.e., not deltas) whose magnitude fits some-axis order.
cheers, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
What JSchell said.
Every charting software "warns" about "unsorted" series data (performance).
In this case, "time-series" data.
One looks at the data; one looks at the charts; one looks at reports.
Everything is practically screaming: "sorted the same".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yep, and that's kind of what I implied in my comment:
I assume 'x,y' refers to a list of discrete 'Point (i.e., not deltas) whose magnitude fits some-axis order. But, let me ask you to respond to what I said to JSchell:Quote: think one additional factor in ... perhaps ... making a SortedList a less viable choice in many situations is the ease of sorting, and/or grouping, etc., using Linq.
What do you think ? thanks, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
(And that's what I implied with "series data" and "charting components").
Re: SortedList
It's a "message" to whomever contemplates that "list" outside of its immediate context.
It's more "intuitive" in terms of its purpose.
It's a (sort of) "typed" list.
Your position seems to be you can always "sort" it. It's a questionable strategy when there is little practical use "unsorted".
What about debugging? Why contend with unsorted data even in memory when it makes it more difficult depending on the situation?
Chunked real time data capture? You want to remember to "sort" everytime? Even just to look at it?
You're trying to generalize something which varies in "value" depending on the situation; while value is in the eyes of the beholder and their "requirements".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: You're trying to generalize something which varies in "value" depending on the situation; while value is in the eyes of the beholder and their "requirements". Uh, no, I am seeking information from my peers, and mentors, here, regarding their use of generic SortedList<>.
With your current response, I am finally getting information from you, and I am up-voting this response
thanks, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
BillWoodruff wrote: given the efficiency of .NET's hash-based data structures ... unless I had a huge SortedList<TKey, TValue> list, frequently accessed, with a large percentage of accesses matching the sort-order
Vast majority of time if "efficiency" is an actual versus hypothetical concern especially in terms of access then the design probably needs to be looked at.
I have used sorted collections because I don't want to figure out how to sort them latter. No consideration at all for efficiency either for individual look up or impacts on insertions. Far as I can recall it was usually because the UI needed it sorted although at least one occasion it was simply because I wanted to log it and wanted it in sorted order.
Very few cases where efficiency was a concern I didn't sort it.
|
|
|
|
|
Thanks, JSchell,
I think one additional factor in ... perhaps ... making a SortedList a less viable choice in many situations is the ease of sorting, and/or grouping, etc., using Linq.
What do you think ?
cheers, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
BillWoodruff wrote: What do you think ?
Sure - deferring it to some other layer (probably because it is the other layer that actually needs it.)
|
|
|
|
|
Hello Guys ,
I am trying to recover the value of a total score on this request. I have this error in sql server.
Invalid column name 'NoteTotal'.
BEST REGARDS !
Someone has an idea, here is my Sql Query!
<pre>select personnelId, Nom, Prenom,
sum(case
when Tbl_Reponses.codeReponse = Tbl_ReponseEntree.codeReponse and Tbl_Reponses.isCorrect =1
then Tbl_Questions.scoreTotal*1
when Tbl_Reponses.codeReponse = Tbl_ReponseEntree.codeReponse
and Tbl_Reponses.isCorrect =1 and Tbl_ReponseEntree.CodeJustificationReponse !=0 and
Tbl_JustificationReponses.CodeJustificationReponse=Tbl_ReponseEntree.CodeJustificationReponse and
Tbl_JustificationReponses.Iscorrect = 1 then Tbl_Questions.scoreTotal*1 else 0 End) AS NoteTotal, NoteTotal/3 as Moyenne
from Tbl_ReponseEntree, Tbl_Reponses, Tbl_Questions, Tbl_JustificationReponses, Personnel,
Tbl_FormulaireExercices where Tbl_ReponseEntree.codeFormulaireExercice =4 and
Tbl_Reponses.codeReponse=Tbl_ReponseEntree.codeReponse and Tbl_Questions.CodeQuestion=Tbl_Reponses.codeQuestion
and Tbl_Questions.CodeQuestion=Tbl_ReponseEntree.codeQuestion and
Tbl_JustificationReponses.CodeJustificationReponse=Tbl_ReponseEntree.CodeJustificationReponse and
Tbl_FormulaireExercices.CodeExercise=Tbl_ReponseEntree.codeFormulaireExercice and
Tbl_ReponseEntree.PersonnelId= Personnel.PersId group by Tbl_ReponseEntree.personnelId, Personnel.Nom,
Personnel.Prenom
|
|
|
|
|
Member 10532748 wrote: NoteTotal/3 as Moyenne Remove that part and try again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
... AS NoteTotal, NoteTotal/3 as Moyenne
You only "just" defined "NoteTotal" ... you don't get to "use it" at the same time (at this query level); particulary since it is related to a grouping function.
You need to pass it to a subsequent "query" in order to operate on it (in this scenario); or rewrite the query altogether.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I create a text file like :
1,2,3,4,5,6
2,3,4,5,6,7
3,4,5,1,2,3
this is an example
Now i need to display the individually from the specified line for example if enter a 2 in a textbox then we need to display in another textbox as 3 and another textbox as 4 .how can i do it
|
|
|
|
|
Read in the data into a string[] . You can then use string.split to separate the numbers.
|
|
|
|
|
Read each line, and use the String.Split Method (System)[^] to break it:
string[] separatedValues = inputLineOfText.Split(','); It returns each value between the commas as a separate string.
You can then load the values into your TextBoxes in the usual way.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Create 3 string arrays; split on ",".
Locate the index of the value entered (eg. 2) in array 1 (eg. 1).
Then use that index to retrieve the corresponding values from arrays 2 and 3 (i.e. 3 and 4).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have an application that draws a 3D perspective view of a surface plot with axes. The user can rotate the view about 3 axes. The drawing is done using OpenTK. The axes are annotated with text using QuickFont. Unfortunately I have found issues:
1) QuickFont disables the ability to transform the model view multiple times. It would appear that the projection and model view are fixed once a value is assigned to the QuickFont.QFontDrawingPimitive.ProjectionMatrix field. For example, set a matrix view, draw text, draw some lines, transform the matrix view by 90 degrees about an axis, draw the same lines as before. The second set of lines are drawn as per the first i.e. not rotated. Remove the code that draws text, and then the lines drawn as expected i.e. the second set is 90 degrees to the first set.
2) When I draw text, the lines and the surface shading change colour to dark blue. If I comment out the text code, the lines are white and the surface is coloured.
Yes I have searched using Google and no I was unable to solve this. All of the examples I have seen are rather simple, with text and shapes drawn in 2D for example.
Update: It looks as if QuickFont either has bugs, or is not compatible with the OpenTK build I am using. In any case, I have written my own code to display strings, which allows the strings to be displayed in 3D, with perspective, rotations and translations as required. I may post sample code if I get the time as it might help others.
modified 9-May-18 3:34am.
|
|
|
|
|
I need help with binding JSON data generated from REST API call to rows in a table in MVC.Below is the code for Controller
public ActionResult Members()
{
var jsonString = "{\"roleMappings\":[{\"user\":{\"id\":\"4b147d87-64eb-4049-bbd3-ade96d18af89\",\"name\":\"PFRENC17\",\"actualName\":\"French, Phil (P.)\",\"displayName\":\"French, Phil (P.) (PFRENC17)\",\"email\":\"pfrenc17@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1502803623890,\"isDeletable\":true},\"role\":{\"id\":\"3de854ce-34ed-4b7f-9b99-9fdf04c0345c\",\"name\":\"Developer\",\"description\":\"Application Developer\",\"isDeletable\":true}},{\"user\":{\"id\":\"3afd930e-9608-4257-a962-0a82b792a6e9\",\"name\":\"RSIEGLE3\",\"actualName\":\"Siegler, Ryan (R.)\",\"displayName\":\"Siegler, Ryan (R.) (RSIEGLE3)\",\"email\":\"rsiegle3@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1500300166062,\"isDeletable\":true},\"role\":{\"id\":\"3de854ce-34ed-4b7f-9b99-9fdf04c0345c\",\"name\":\"Developer\",\"description\":\"Application Developer\",\"isDeletable\":true}},{\"user\":{\"id\":\"33dd9fea-4685-4505-91ba-5c0508301b56\",\"name\":\"Michael3\",\"actualName\":\"Michael (Y.)\",\"displayName\":\"Michael (Y.) (Michael3)\",\"email\":\"Michael3@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1522249840141,\"isDeletable\":true},\"role\":{\"id\":\"f722b338-01c1-43cb-bc53-853cfb0d2249\",\"name\":\"UC Auto Discovery\",\"description\":\"\",\"isDeletable\":false}},{\"user\":{\"id\":\"33dd9fea-4685-4505-91ba-5c0508301b56\",\"name\":\"Michael3\",\"actualName\":\"Michael (Y.)\",\"displayName\":\"Michael (Y.) (Michael3)\",\"email\":\"Michael3@abc.com\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1522249840141,\"isDeletable\":true},\"role\":{\"id\":\"8421e59e-ce5f-477b-aa6f-0313aa1223e6\",\"name\":\"Application_Lead\",\"description\":\"Development Team Lead\",\"isDeletable\":true}},{\"user\":{\"id\":\"5599437f-68f9-4c20-bd0a-5c26d55628e1\",\"name\":\"UBLDUCD1\",\"actualName\":\"Blducd1, U (U.)\",\"displayName\":\"Blducd1, U (U.) (UBLDUCD1)\",\"deleted\":false,\"deletedDate\":0,\"authenticationRealm\":\"f4191d4b-4331-4637-af6f-c89781687bf6\",\"isLockedOut\":false,\"lastLoginDate\":1515694447960,\"isDeletable\":true},\"role\":{\"id\":\"8421e59e-ce5f-477b-aa6f-0313aa1223e6\",\"name\":\"Application_Lead\",\"description\":\"Development Team Lead\",\"isDeletable\":true}},{\"group\":{\"id\":\"7862c275-8eb2-42cf-895c-214c2826a0b8\",\"name\":\"config_viewer\",\"enabled\":true},\"role\":{\"id\":\"ba4cdbf1-6b97-436f-9b40-a7e21d8394f2\",\"name\":\"ReadOnly\",\"description\":\"Read-only access\",\"isDeletable\":true}}],\"id\":\"877eb9b9-6dd9-432d-b55a-01bd406d039a\",\"name\":\"AftImport Team\",\"isDeletable\":true}";
List<string> MemberNames = new List<string>();
var t = JObject.Parse(jsonString);
var pt = t["roleMappings"];
var COUNT = 0;
foreach (var v in pt)
{
if (COUNT > 4)
{
break;
}
var p = v["user"]["name"];
MemberNames.Add(p.ToString());
COUNT++;
}
return View(MemberNames);
}
Below is the code for View
<table border="1" align="center" style="font-family:Arial; width:900px;">
<tr height="50">
<th>Member</th>
<th>Roles</th>
<th>Actions</th>
</tr>
@foreach (var d in Model)
{
<tr height="30">
<th>@d</th>
<th></th>
<th><button class="editbtn">Delete User</button> <button class="editbtn">Change Role</button></th>
</tr>
}
</table>
As I have binded json data to the "Member" field in View to the Controller, I need help with binding "Roles" field in View to
"name": "Application_Lead", . I need Roles to be displayed on web page. Typical roles in the above JSON string are "Developer", "Application Lead"
|
|
|
|
|
But you are not returning those fields at all, the only thing you are returning is the name of the user in each of the element. See here,
List<string> MemberNames = new List<string>();
var p = v["user"]["name"];
MemberNames.Add(p.ToString());
return View(MemberNames);
You need to change the object that you are returning and then capture the values returned. Rendering the object will be as simple as,
foreach (var item in Model) {
<tr>
<td>@item.Name</td>
<td>@item.Role</td>
</tr>
}
Take my advice, return all the "required" fields, as an anonymous separate object (if you like). That way, you will contain every bit of information that you require on the client-side, and there you can render it easily.
Secondly, eyeballing the fields etc won't be a good approach. Consider mapping the fields from the database, and only capture those that are needed.
Consider reading my article about somewhat similar topic as well, From zero to hero in JSON with C#.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you for responding. Could you share about the code in the Controller. How to create an object and capture the values returned. Should I be using "Dictionary" or "List"
|
|
|
|
|
I would like to add a dropdownlist to my gridview and then selecting an avaliable table from that list. The selected table would show and i could edit it.
I already have a form made with grid view and an option to update and show record in a table. It looks like this:
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
SqlDataAdapter sda;
SqlCommandBuilder scb;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void button1_click(object sender, EventArgs e)
{
scb = new SqlCommandBuilder(sda);
sda.Update(dt);
MessageBox.Show("Records updated");
}
private void button2_click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=GECKO-PM\\SQLEXPRESS;Initial Catalog=Gecko;Integrated Security=True");
sda = new SqlDataAdapter(@"SELECT ID_vzdrzevanje, Datum, Lokacija, Ime_vrtine, Delo FROM Vzdrzevanje",con);
dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
Thanks
|
|
|
|
|
I think you want to add the "drop down list" to the form; and NOT the grid.
The code you show has NOTHING to do with that.
So, show something that is relevant if you want help.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes im sorry, combobox is added on the form.
Now i've added this code to link combobox so it show all of my tables from SQL database:
String strConnection = "Data Source=GECKO-PM\\SQLEXPRESS;Initial Catalog=Gecko;Integrated Security=True";
SqlConnection con = new SqlConnection(strConnection);
try
{
con.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = con;
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "Select table_name from information_schema.tables";
SqlDataAdapter sqlDataAdap = new SqlDataAdapter(sqlCmd);
DataTable dtRecord = new DataTable();
sqlDataAdap.Fill(dtRecord);
comboBox1.DataSource = dtRecord;
comboBox1.DisplayMember = "TABLE_NAME";
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Now i would like to link a button with combobox so when i click on button it shows content of selected table in combobox. Or perhaps if the the table is automaticly shown when it is selected in combobox. Any ideas?
|
|
|
|
|
UPDATE:
I have managed to get the chosen table from combobox be shown on the grid view when clicked on a "show table" button. The code on the "show table" button looks like this:
string selected = this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
SqlConnection con = new SqlConnection("Data Source=GECKO-PM\\SQLEXPRESS;Initial Catalog=Gecko;Integrated Security=True");
sda = new SqlDataAdapter(@"SELECT* FROM dbo."+selected,con);
dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
Be tuned for further improvments or question for help.
|
|
|
|
|