w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » C# » Page 37
Writing data from multiple list box into excel columns in c#
It's difficult for me to determine the full details of your configuration, but if it's as simple as two ListBox controls for which you're writing values, you could easily do something like the following: var sw = new StreamWriter(@"output.csv"); var csvWriter = new CsvHelper.CsvWriter(sw); int lbxCount = lbx.Items.Count; int ptrCount = ptr.Items.Count; for (int i = 0; i < Math.Max(lbx.Items.Co

Categories : C#

OxyPlot - removing the values of a LinearAxis and leaving only the title
If the labels 0, 100, 200 belong to one axis and the texts "Day One", ... to the other one you can set the colors of the labels of the first axis to transparent like this axis.TextColor = OxyColors.Transparent; Hope this helps.

Categories : C#

regexpression allowing semicolon through
You need to place the negation operator inside of your class instead of applying it as the beginning of string anchor. Regex.Replace(st, @"[^a-zA-Z0-9 .()/-]+", String.Empty); Example: String s = @"foo/bar ''''(baz.) """"12-34;:;;!%$@"; String r = Regex.Replace(s, @"[^a-zA-Z0-9 .()/-]+", String.Empty); Console.WriteLine(r); //=> "foo/bar (baz.) 12-34"

Categories : C#

DownloadString and Special Characters
DownloadString doesn't look at HTTP response headers. It uses the previously set WebClient.Encoding property. If you have to use it, get the headers first: // call twice // (or to just do a HEAD, see http://stackoverflow.com/questions/3268926/head-with-webclient) webClient.DownloadString("http://en.wikipedia.org/wiki/Maurício"); var contentType = webClient.ResponseHeaders["Content-Type"]; var c

Categories : C#

Why does my program's control flow seem to jump around when stepping through a factorial method?
The method is recursive, so it will call itself. When you call factorial(6) to calculate 6*5*4*3*2*1, it will in turn call factorial(5) to calculate the part 5*4*3*2*1 and multiply that with 6. The call to factorial(5) will in turn call factorial(4) to calculate 4*3*2*1 and multiply that with 5. So it will keep calling itself until the call is factorial(1) and the first part of the if statement

Categories : C#

Best loop to remove children with bottom-up deletion in a treeview?
Here's what I came up with: an item model that can be constructed with a friendly syntax (no need to set its parent) a pruning tool that will remove an item and cleanup the hierarchy as much as it can Example (pruning item 1.4.1.1) before: after: Objects: Item : your item it watches for childrens you add to it and (un)sets its Parent property provides Prune method which removes it f

Categories : C#

What is the best way showing Folders' content using Xamarin iOS in C#?
I think nobody will not reply my question. Well I would like to share my solution.. I called the tableview in the same tablewView. First of All, I entered a storyboard id for the tableview controller name is commonstoryboard so after my code is like that var item = (profileLists[indexPath.Row] as QuickSearchProfile); var result = search.GetQuickSearchProfile(item); // FillTable(resul

Categories : C#

Linq query to orderby level then parent and child item
Have your Assembly class implement IComparable which allows you to define how they are ordered by implementing its only method: CompareTo() I THINK you were saying that you need to order first by Level, then Parent, then Component. If so you could use something like this: class Assembly:IComparable { public int Level { get; set; } public string Parent { get; set; } public string Comp

Categories : C#

Is it possible to connect to a nanomsg socket from a C# client?
Sockets are sockets. They abstract network protocols, like TCP and UDP, and send bytes back and forth. So yes, you can use Socket to connect to any other remote endpoint using TCP, even if that endpoint isn't even using sockets as their implementation. Of course, you still have to be able to interpret the bytes. But that's not the job of the Socket class. It's only there to provide the connectio

Categories : C#

How to enable my Azure site as https instead of http?
You have to add binding configuration with <security mode="Transport" />. So your config should look like this (first the section that does the trick). <bindings> <webHttpBinding> <binding name="HttpsConfiguration"> <security mode="Transport" /> </binding> </webHttpBinding> </bindings> Followed by the whole file architecture. &l

Categories : C#

Thread-safe server
It looks like you are closing the output stream prematurely. In GetRequestProcess(), just remove that call to stream.Close(). That will let the writer flush to the stream when it's closed. You don't need to explicitly close anything as long as you are correctly disposing objects (as you appear to be here). As for the rest of your questions, I recommend you post a different question, without all t

Categories : C#

Iterate through a byte array like it's Uint16[]
No, C# doesn't offer a way to safely reinterpret one object as if it were some different type of object (you can do it with unsafe code, but then the whole assembly winds up "unsafe"). You can use BitConverter.ToUInt16(), or even wrap the byte[] in a MemoryStream and use the BinaryReader.ReadUInt16() method to read from the byte[] object. But judging from the wording of the question, you don't wa

Categories : C#

Array value resets automatically
You are not resetting anything. You declare a new int array (as in: a new object) every time the selected value changes! That's why the length of the array in the other method is always 0: Because it's still the global empty int array. int[] xValues = { }; //declaring empty array private void comboBox1_SelectedValueChanged(object sender, EventArgs e) //using selection

Categories : C#

WPF C# - Combobox data to number for database
For something simplistic, you can use comboBox.SelectedIndex + 1, but that will break down if the order of your items changes somehow. For something slightly more elaborate, you could do the following: namespace ComboBoxExampleWPF { class UserLevel { public UserLevel(int level, string description) { Level = level; Description = description;

Categories : C#

How to move the player to a specific point in a 2D Unity Game
Try the following code Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position); float targetX = 100; // replace it with your value float targetY = 100; // replace it with your value if (screenPosition.y > Screen.height || screenPosition.y < 0) { transform.position = Camera.main.ScreenToWorldPoint(new Vector3(targetX, targetY, camera.nearClipPlane)); }

Categories : C#

Algorithm - Find the midpoint of an arc
Assuming A, B, M and Center are objects of some vector type with the usual operations: var a = A-C; var b = B-C; var m = a+b; m is a vector that goes from Center towards M. Therefore: m = m.Normalize() * Radius; M = Center + m; Please note: This algorithm does not assume an order of A and B, and always interprets the arc as the smaller of the two possible ones. Without adding special cases,

Categories : C#

Getting data from GridView after changing the DataSource
The databound event runs for each record in the gridview. So one issue is that each time you are clearing out the items you added before. Another issue is that you need to get the data from the EventArgs instead of from the gridview.columns since those are not there until after all the data is bound. I think all you need to do is get the data from the header row: protected void GridView2_DataBoun

Categories : C#

Formatting String in Razor with String.Format not working correctly
Check your console, my guess is you're getting a JS error causing the alert to fail. Here's your code with output along with an alternative way to do this with regexes. var number = "1112223333"; //an alternative method using regexes var regexFormat = Regex.Replace(number, @"^(d{3})(d{3})(d{4})$", "($1)$2-$3"); //The methods you provided string formattedNumber = String.Format("{0}{1}{2}", numbe

Categories : C#

Auto fill-in username + password when user clicks a website link
I figured out how to do this. Make a new HTML page and add the code below to it. When done, you can create a link wherever you wanted and make the source equal to the HTML page you just created. <html> <head> <title>Automatic Login</title> </head> <body onload="document.forms['securelog'].submit();"> <form action="[enter the login

Categories : C#

c# - get multiple listbox values and turn into comma separated string winforms
You need to loop over the SelectedIndices collection, retrieve the TestSubject object stored in the Item corresponding to the index selected and then add its TestSubjectID value to a list of integers. Finally string.Join will create the string for you. List<int> ids = new List<int>(); foreach(int x in lbTestSubjects.SelectedIndices) { TestSubject t = lbTestSubjects.Items[x] as Tes

Categories : C#

JSON parsing takes way too long
I would create an class for response object, and then use code similar to the following. I tested on a 2.8MB json file and it averaged about 1.2 second, also try using fastJSON (there is a nuget package) - it is the fastest parser I have found. string fileName = @"c: empjsonyourfile.json"; string json; using (StreamReader sr = new StreamReader(fileName)) {

Categories : C#

Cannot process 'StudentGrantsWF.xaml' because it is not an EDMX file
It happened that I was searching for the error and find this question Cannot process 'reportname.rdlc' because it is not an EDMX file one of the answers pointed out that it might be a naming clash specifically if I have an entity that has a similiar name, though not exact name. Changing the name worked for me but I had another problem as edited in the question! Yet I hope this solution a

Categories : C#

System.AccessViolationException with SQLite
CL. deserves credit for this; he mentioned that SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads. This approach fixed the problem: using Microsoft.Win32; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Data.SQLite; using System.Diagnostics; u

Categories : C#

Which Entity Framework Initializer should i use to permanently store my data?
You don't need to set any initializer, but your class has to set this data once, and check if the database already has data in the data before add them again. So, if you want to keep the data exactly as it is, you need to set the initializer by null So, Something like this : public class BloodBankContext : DbContext { public BloodBankContext() : base("BloodB

Categories : C#

Custom ToolTip template for some elements
Following your current approach, you can try using some DataTrigger listening to the PlacementTarget to check its Type and set the Template accordingly. So we need a Converter here (to convert the PlacementTarget to its Type). Here is the working code: <Style TargetType="ToolTip"> <Style.Resources> <local:ElementToTypeConverter x:Key="typeConverter"/> </Style.Reso

Categories : C#

NHibernate save children element FK going NULL
Your logic (e.g. Add() method in Parent, Inverse() mapping) was OK. You were almost there. There is only one BUT... In general, the proper (if not only correct) solution is to use objects to express realtion and not just the ValueType/int values. That's why we call it ORM - Object-relational mapping Object in C# should look like this: public class Parent { ... // correct mapping of the c

Categories : C#

Clipboard.SetFileDropList doesn't work fine
The Clipboard class can only be used in threads set to single thread apartment (STA) mode. The options to do this are Mark Main method with the STAThreadAttribute attribute. OR Create a STA thread from your application and use Clipboard Example code for option #2 System.Collections.Specialized.StringCollection stC = new System.Collections.Specialized.StringCollection(); stC.AddRange(Sys

Categories : C#

ConfigurationManager vs Properties
ConfigurationManager is a general purpose set of classes to manipulate application and web configuration files and their structures. Properties.Settings is a subset of this functionality allowing the quick and simply manipulation of the Application Settings portion of that file. I've only ever used Properties.Settings for my user specific stuff, I use the rest of the application config file for t

Categories : C#

Generate unique Id (Entity Framework)
First: there is no way for EF to create a compound key unique value. Please, see this SO answer. Second: your database is denormalized. You need to normalize it. There is a cart which can have several products, then: you need a cart table, which has the cart id (can be a single PK, generated by the DB using identity, and this is supported by EF). This cart must only have data related directly t

Categories : C#

Get values from selected item in listview using asp.net c#
this is the handler of GRidView Events not listView Events GridView1_RowCreated() Actually I have the same issue as you ,, and I found a way to get the id of selected raw ,, int id =(int) ListView1.SelectedDataKey.Value; // if the Id is // the datakey which i think the primary key"" and if you want to get the data of different column in the selected listView raw:: Li

Categories : C#

Visual studio wpf events
Here is a simple code snippet that will probably help. Assuming that you have a WPF button named btnControl in your XAML, you can add the following click event handle to the code behind (MainWindoww.xaml.cs) module: btnControl.Click+=(s,e)=> { // put your click event proc code here }; Note: you do not need to modify your XAML. Hope this will help. Regards,

Categories : C#

Incomplete undo on local context with Entity Framework
If you mark an entity as deleted (EntityState.Deleted) I'm surprised the documentation would state a Reload() would undo a delete. Instead, try using the same code for Modified for Delete. switch (entry.State) { case EntityState.Modified: entry.State = EntityState.Unchanged; break; case EntityState.Added: entr

Categories : C#

Passing constructors with arguments?
Your Initialize method does not have any kind of "Position" variable declared in scope. For example, you might do something like this: myClass myClassInstance; protected override void Initialize() { // variables defined in a function are typically lower-case in C# Vector2 position = new Vector2(0,0); // I changed "Position" to "position" to match the variable myClassInstance =

Categories : C#

JSON.NET: Unable to translate Unicode character
It's not a JSON problem, it's a StreamWriter problem, it encounters a character that it cannot encode. Try to open it like this: using (StreamWriter sw = new StreamWriter(fs, Encoding.Unicode))

Categories : C#

Calling my function in webBrowser1_DocumentCompleted does not finish loading the browser
(Making comment as answer to allow question to close) I'm pretty sure the issue that the video you linked is Adobe Flash. However taking the screenshot with selenium might work.

Categories : C#

Microsoft.AspNet.Identity and Umbraco
I ended up in dependency hell trying to get this working in v6.2.4 but you should be ok in the latest v7 if you want to try this https://github.com/Shazwazza/UmbracoIdentity. It's a project started by one of the lead developers on the Umbraco Core team. Simon

Categories : C#

How to get the value using XPath and using Parameter?
You want to include the string contents of the parameter in the XPath query? This should work: var xPathQuery = String.Format("//a[contains(.,'{0}')]", p0); driver.FindElement(By.XPath(xPathQuery)).Click();

Categories : C#

convert free functions to classes
Assuming you wrote earlier code like: this.Load += this.onPageLoad; or Load += new EventHandler(onPageLoad); You can instead write: var name = new Name(); this.Load += name.onPageLoad;

Categories : C#

How do objects NOT implementing INPC notify changes?
I am not sure but I think........ Your Persons property implements INotifyPropertyChanged interface and so, Indirectly all the objects or properties in your Person class also implements INotifyPropertyChanged. I might be wrong in this case. ObservableCollection also implements INotifyPropertyChanged internally. So, there is no requirement to implement INotifyPropertyChanged in Persons Property.

Categories : C#




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.