w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » C# » Page 3
Simplify nested loops?
You need a recursive function foreach (var i in mlist) { checkChildren(i); } and then void checkChildren( List i ) // i is of type List? { if (i.key == dto.under.ToString()) { // add this as a child i.children.Add(m1); // what is m1? you may have to pass // this in as a parameter. I am not // really sure what it is } if (i.children.

Categories : C#

Binding to a TextBox inside an ItemsControl ItemTemplate
You cannot bind to elements in a collection and then change the element itself--you can only change properties of this element through the binding. In other words, given the following collection [ "one", "two", "three" ] through a binding such as <TextBox Text="{Binding Words[0]} /> <!-- the word "one" is displayed in the tb --> if you change "one" to "derp" you would not al

Categories : C#

Fill a rectangle with an image using Mono Cairo Library
I found the solution. I was setting the source at the wrong place. Below is the right code Cairo.Rectangle imageRectangle = new Cairo.Rectangle(50, 100, width, height); ctx.NewPath(); Cairo.ImageSurface imgSurface = new Cairo.ImageSurface("C:/Temp/Image.png"); float xScale = (float)imageRectangle.Width / (float)imgSurface.Width; float yScale = (float)imageRectangle.Height /

Categories : C#

Multiple colored Activity Label element on Xamarin.Android
Look at SpannableString in the Android documentation. http://developer.android.com/reference/android/text/SpannableString.html var textView = FindViewById<TextView>(Resource.Id.my_label); var span = new SpannableString("My Label"); span.SetSpan(new ForegroundColorSpan(Color.Red), 0, 2, 0); // "My" is red span.SetSpan(new ForegroundColorSpan(Color.Blue), 3, 8, 0); // "Labe

Categories : C#

filesystemwatcher check last detection
Create a timestamp that represents the next valid time to process the event. Then, in the event handlers, check the current time against that time. Public Class MyClass Dim NextValidTime as DateTime public sub Some_Event_Handler() If Now() > NextValidtime Then 'do stuff NextValidTime = DateAdd(DateInterval.Second, 1, Now) Else ' Not

Categories : C#

Non-generic implementations of generic interfaces
Just because ExampleEntry can be implicitly converted to an IEntry does not mean that an IRow<ExampleEntry> can be converted to an IRow<IEntry>. If IRow is covariant with respect to its generic argument, then yes, that would be possible, but it's not as it stands, so the implicit conversion isn't possible. If you could implicitly convert an IRow<ExampleEntry> to an IRow<IEnt

Categories : C#

From a API stand point, wait for a task -- but don't block UI
First off, you need to separate your concerns. MyApiManager should not know anything about UIs. It manages APIs, and according to the Single Responsibility Principle, that's all it does. Read Stephen Toub's Should I expose synchronous wrappers for asynchronous methods? It should be the UI event handler's responsibility to make sure MyApiManager does not block the UI. So, change your event hand

Categories : C#

How can I convert my query featuring RowNumber() to LINQ?
This works in memory with an array. Not sure how well it will translate into database calls. (Update: restructured code so the important part is on top) void Main() { var Emps = Emp.GetData(); var q = (from d in (from e in Emps group e by e.DeptNo) select d.Take(2)).SelectMany(e=>e); q.Dump(); } // Boring setup details class Emp { public int EmpNo

Categories : C#

Understanding the structure
That's because Class2 become a nested class. You can create it like this: Class1.Class2 class2 = new Class1.Class2(); then you can use his property like all normal instances: class2.Age = 0; class2.Dob = 0; But i think that waht you are trying to achieve is to have a property to the type of your Class2: public class Class1 { public string FirstName { get; set; } public string LastNa

Categories : C#

How do you change an enum value to a more readable string that is bound to a UltraGrid?
I just create a property that returns the description and bind to it public override string UserTextOp { get { Type enumType = typeof(enumTextCond); string name = Enum.GetName(enumType, cond1SelectedKeyEnum); if (name != null) { FieldInfo field = enumType.GetField(name); if (field != null) { DescriptionAt

Categories : C#

Add data to a TextBox from a DropDownList in a DetailsView field
Can you try this on code behind? protected void DetailsView1_ItemCommand(object sender, System.Web.UI.WebControls.DetailsViewCommandEventArgs e) { if (e.CommandName == "Update") { DropDownList yourddl = DetailsView1.FindControl("yourdropdownlist"); if (yourddl.SelectedIndex > 0) { var tbox = DetailsView1.FindControl("yourtextbox"); tbox.text =

Categories : C#

Accessing XML RPC Interface
i finally found the solution. you still have parse the xml encoded response but now i finally get an response. System.Net.ServicePointManager.Expect100Continue = false; byte[] requestData = Encoding.ASCII.GetBytes("<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName></methodCall>"); HttpWebRequest request = (

Categories : C#

Am I obliged to call EndPeek after using BeginPeek?
Giving a proper answer to this question takes some effort, because the short answer ("no") could be misleading. Does the API description explicitly say you must call EndPeek() for every call to BeginPeek()? Not in any topic I could find, and not only that, it appears to state the opposite here: To use BeginPeek, create an event handler that processes the results of the asynchronous operatio

Categories : C#

MVC RouteConfig routes one path to Controller but not another
By default, MVC does not route static files and just tries to serve a static .css file under the requested path. Just remove the .css ending and the route will be used. Edit: To be clearer the IIS tries to serve these static files before the MVC routehandling even comes into play.

Categories : C#

How to map a class containing a property that is a derived class
I think nHibernate should figure it out, if you have subclasses mapped correctly. Just mapp a relationship between Foo and Thing (https://github.com/jagregory/fluent-nhibernate/wiki/Fluent-mapping - chapter Relationships - you have maybe one-to-one or many-to-one).

Categories : C#

How to unload menus (UIViewControllers)
viewWillAppear: method gets invoked every time the controller's view is about to be displayed. Whenever you make a transition to and fro from a controller, it would be invoked. From Apple's documentation(iOS Developer Library) : This method is called before the receiver's view is about to be added to a view hierarchy and before any animations are configured for showing the view. You can

Categories : C#

how to pass a List in the model as a parameter of an ajax call?
If I am reading the question correctly you want to return a JsonResult and just return a List<Persons>. You'll then get that result and bind it to whatever you are displaying the results in: a grid, list, etc. You'll likely want to look into some sort of client templating library to make this easier. You can certainly use jQuery to do all this, but something like handlebarsjs would make it

Categories : C#

ASP.NET MVC on Azure Run Job "Every Hour"
As it was already mentioned in the comments, you would be better off separating "long-running" task from your website, you can still keep it in the same solution, as separated project, to make sharing business logic code simpler and just deploy to two different environments - Website + WebJob, Website + WebWorker You can try to mitigate the issue with long running task on IIS, see some resources

Categories : C#

TPL Dataflow Consumer to Process Multiple Items at a time
Your use of TPL Dataflow is rather strange. Normally, you'd move the consumption and processing into the flow. Append a TransformBlock to call the webservice. Delete ConsumeValues. ConsumeValues executes sequentially which is fundamentally not what you want. Instead of BoundedCapacity I think you rather want MaxDegreeOfParallelism.

Categories : C#

Perform Multiple Async Method Calls Sequentially
Yes, this is the correct way. They will execute sequentially. The important quote from the msdn: The await operator tells the compiler that the async method can't continue past that point until the awaited asynchronous process is complete. If you wanted to execute them in parallel, you'd have to use something like this: var t1 = DoTaskAsync(...); var t2 = DoTaskAsync(...); var t3 = DoTaskA

Categories : C#

Fetch row and Save in Variable
I sort it out myself SqlCommand cmd = new SqlCommand("SELECT * FROM users WHERE (username = '" + uname + "') AND (password = '" + pass + "');", conn); SqlDataAdapter da = new SqlDataAdapter(cmd); cmd.ExecuteNonQuery(); SqlDataReader dr = cmd.ExecuteReader(); Here it is guys, i hope it help noobs. You can fetch it with dr.Read()

Categories : C#

error in insert data to access database
Try to change the Mobile Phone number data type to string in your function and to varchar(10) in your database. It is not good idea to set it as numerical variable. Then try to remove "" from your Id column, while data entry. After doing these steps, it may work fine

Categories : C#

Upload File from jQuery AJAX POST
If you're already sending it successfully in PHP, you can get access to the same variable in C# by referring to the HttpContext.Current.Request.Files variable. HttpContext.Current.Request.Files["postedFileName"] will give you access to a HttpPostedFile object, which allows you to access the InputStream, FileName, ContentType, and other properties.

Categories : C#

how can i access the checked status of each checkbox in a datagridview control in c#?
You can use the CellContentClick-event but you have to check if it's the right cell: private void DataGridView_CellContentClick(Object sender, DataGridViewCellEventArgs e) { DataGridView grid = (DataGridView)sender; var chkCell = grid[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell; if (chkCell != null) { bool checked = (bool)chkCell.EditedFormattedValue; /

Categories : C#

List of List of struct not serializing. System.RuntimeType is inaccessible due to its protection level. Only public types can be processed
It's probably the public Type Type { get; set; } field, holding a reference to a RuntimeType instance which causes the error. RuntimeType is not serializable, that is what the error message tells you.

Categories : C#

How to change the colour of an MVC webgrid row text depending on some condition
Try to put this right under your @grid.Html() @Scripts.Render("~/bundles/jquery") <script type="text/javascript"> $('tr').each(function (index) { //iterate over all table rows if (index > 0) { //skip header if ($(this).children('td:nth-child(3)').text() < 31) //look for the 3rd td in each row. thats where your age is. { $(this)

Categories : C#

How to sync only certain rows in a database
Could you maybe use a SQL function for the filter-parameter so this can change? Something like serverTemplate.Tables["tableA"].AddFilterColumn("ModuleId"); serverTemplate.Tables["tableA"].FilterClause = "[side].[ModuleId] = sf_GetCurrentModule()"; You could create a SQL function sf_GetCurrentModule() to return the ModuleId to be synched. If the rows to be synched vary from client to client, yo

Categories : C#

Switch-case of EventArg types
In switch case block each case must be evaluated statically. This means that you need a constant in each case. This post maybe useful also C# switch statement limitations - why?

Categories : C#

Cumulative sum of stock movements when dates and id is not in the same order
Your problem is that your Date field does not have enough granularity to properly order on that field. what happens here is that, if you sort a field, by default it maintains the order before the sort when there are conflicts. You're already trying to mitigate this with (stockMovement1.ShippingBill.Date == stockMovement2.ShippingBill.Date ? stockMovement1.ShippingBill.Date >= stockMovemen

Categories : C#

The call stack never gives the location of the error
Use the Exceptions dialog, set the debugger to Break on User-Unhandled Exceptions. In Visual Studio's menu, Open Debug -> select Exceptions... -> check the first Checkbox for the Command Language Runtime Exceptions. Edit: just notice that you are using Express version of 2012. As per the link, To enable the Exceptions menu in Express versions, on the Tools menu, click Settings, and then se

Categories : C#

C# - TextBox_TextChanged event - revert to previous value
What i would do(not sure if it is the best option) is to make a variable and set its value at the end of your TextChanged. that way, the next time it will enter the TextChanged, you will still have the value of your previous change. string txt = ""; private void txtFCServerURL_TextChanged(object sender, EventArgs e) { if(txtFCServerURL.Text != txt) {

Categories : C#

TreeViewItem toggle doesn't work with custom style
When you add Border, which becomes root element of your template, you need to move VisualStateGroups from Grid to that Border (top level element of your ControlTemplate) <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}"> <!-- other setters --> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Ty

Categories : C#

Saving .NET user settings takes very long time
First suggestion: The calls to retrieve paper sources and paper sizes are being passed through to the driver. Your best bet is going to make sure that the newest version of the driver is installed. It's possible that older versions of the driver (in particular, those from the CD that came in the box) are old and buggy. If you haven't already, hit the manufacture's website, and grab the latest. S

Categories : C#

Code-First Migrations for multiple databases?
You are trying to use a connectionString designed to work with Database First / Model First. You can tell because your providerName is System.Data.EntityClient instead of System.Data.SqlClient. Your connection string should look like this: <connectionStrings> <add name="MyContext" connectionString="Data Source=SQLSERVERDB; Initial Catalog=TestDB_CodeFirst;user id=***;passw

Categories : C#

WPF formatting by Class instead of property?
You may bind color property to instance and write a converter which will return different Brush for different type: Background={Binding Converter={c:InstanceToColorConverter}}, in InstanceToColorConverter's Convert method if statements cascade may be implemented if(value is A)return new SomeBrush();else if(value is B)return new AntoherBrush(); You may also create class Attribute which s

Categories : C#

Type alias on right side of using alias directive
I suppose this restriction is simply to rule out having to worry about situations like the following in the compiler. using X = C<Y>; using Y = C<X>; class C<T> { } Of course the problem is that X is C<Y> is C<C<X>> is C<C<C<Y>>> is ... If the language restriction was looser, disallowing only circular using alias directives, the compiler co

Categories : C#

Generic class inherit from Dictionary with Collection
You can do this class CollectionDictionary<K, C> : Dictionary<K, ICollection<C>> It removes the constraint you had that makes the ICollection have an empty constructor. In order to be able to create new collections you could ask for a delegate that does that. But in your case I think your original solution would produce less boilerplate code. // ctor public CollectionDiction

Categories : C#

regenerateExpiredSessionId for cookieless="UseCookies"
If you use session with cookies enabled asp.net does not allocate memory for session data until a session object is created. Because of this a new session id will be generated for each page request. In this case you can create a session instance inside Session_start event of Global.asax file. Please refer the following link for further information, http://msdn.microsoft.com/en-us/library/system.

Categories : C#

c# object float field is different than database object float field
If you have literally used a SQL float with a C# float, these are not comparable. You should be using a SQL real to store your C# float. See here for full chart: C# Equivalent of SQL Server DataTypes As an aside, you will always have the potential for these issues when working with floating point numbers. Where possible, use a decimal instead. Further reference for SQL float != C# float: Why

Categories : C#




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