.NET Programming

134K

Solutions

39K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

Share tech news, updates, or what's on your mind.

Sign up to Post

I have a Async Function that references a control on the screen.  The control is updated with new information during the running of the function.  Do I place the Await Task.Delay(1) before or after the control is updated?

Btn.text = "One" : Await Task.Delay(1)

or

Await Task.Delay(1) : Btn.text = "One"
0
HOW WOULD YOU RESTRUCTURE THE DATA IN ACCESS or SQL SERVER IN ORDER TO EXECUTE THIS QUERY

QUERY--> "what is the effect of brain region, target location, and timing on kinematic response?"

ID      Parameter      UT_50      UT_0      UT_100      UT_250      MT_50      MT_0      MT_100      MT_250      LT_50      LT_0      LT_100      LT_250
20130318ED      DLPFC 100ms angle      12.32174145      12.99330841      9.198294504      11.52222631      6.340282729      5.765893345      2.356281523      2.816760675      15.21706611      11.67522974      37.53215703      28.62763514
20130415AV      DLPFC 100ms angle      6.643960487      2.681605064      45.47663277      13.03811801      11.46481681      11.70855284      16.70370681      21.46583857      4.024752731      20.52851436      12.07552518      18.812411
20130422PS      DLPFC 100ms angle      27.05474266      24.54031814      13.64629434      22.24167306      17.14609102      10.07054778      7.698115749      15.96791456      12.69933214      29.42852496      13.32754867      13.01389084
20130429AB      DLPFC 100ms angle      13.31082269      11.91017544      6.457531213      9.531094567      6.056097826      8.80621661      6.886299206      7.711310657      3.729936749      3.01717473      6.905232067      9.607273808
20130506JN      DLPFC 100ms angle      5.049545403      5.967528912      3.863780423      15.23849361      12.90741906      11.2606615      6.935865509      8.657818408      4.562420907      24.74435935      14.83554088      18.92366217
20130513WD      DLPFC 100ms angle      36.70301022      26.63866007      14.64716985      6.896767072      62.75687098      17.76465364      23.02631308      34.29193975      18.95470209      15.6362619      5.463278143      21.88485651
20130523VL      DLPFC 100ms angle      16.56186768      3.067840624      17.52907656      15.09035332      8.630383858      16.48188211      7.649123584      18.03464645      37.87583362      10.83250461      25.90015454      21.33974508
0
I'm creating a custom drawn form with its own title bar, footer, resizability, all that fun stuff. I've overridden the WndProc method of the form as follows:
		protected override void WndProc(ref Message m)
		{
			if (m.Msg == WM_NCHITTEST)
			{
				Point cursorPosition = new Point(m.LParam.ToInt32());
				cursorPosition = this.PointToClient(cursorPosition);
				Point resizeZone = new Point(this.FooterRectangle.Right - 16, this.FooterRectangle.Bottom - 16);
				System.Diagnostics.Debug.Print($"{resizeZone} - {cursorPosition}");
				if (cursorPosition.Y <= TITLEBAR_HEIGHT)
				{
					m.Result = (IntPtr)2;
					return;
				}
				if (cursorPosition.X >= resizeZone.X && cursorPosition.Y >= resizeZone.Y)
				{
					this.Cursor = Cursors.SizeNWSE;
					m.Result = (IntPtr)17;
					return;
				}
				else
				{
					this.Cursor = Cursors.Arrow;
				}
			}
			base.WndProc(ref m);
		}

Open in new window

This does a great job of allowing me to drag or resize the window but the one thing that's currently missing is being able to display the window context menu on either a right click or when left clicking on the form's icon in the upper left corner. (Screenshot attached for clarity). Can anyone tell me how this might be accomplished?
Window context menu
0
Hello,
Is there a better and faster way of Application.doevents
Thanks
0
I have an ASP.NET Web Site built in .NET 4.7 using C#. In my web.config, I have the following Forms authentication (see web.config below) with the "domain" attribute set to ".mydomain.com" for my Production environment. Is there a way to dynamically change its value (via C#)  based on the environment, such as QA, Staging, etc. For example, if (Request.Url.AbsoluteUri.StartsWith("http://qa")), then I want to change the value of the "domain" attribute to ".myqadomain.com", and  if (Request.Url.AbsoluteUri.StartsWith("http://staging")), change the value to ".mystagingdomaincom".

Here's the <authentication> section of my web.config:
    <authentication mode="Forms">
      <forms path="/" name="MyWebSite_Auth" loginUrl="~/login.aspx" defaultUrl="~/customers/Default.aspx" protection="All" slidingExpiration="true" domain=".mydomain.com" timeout="350" cookieless="UseCookies"/>
    </authentication>

Please provide the necessary C# code to accomplish this.

Many thanks in advance.
0
When I say Clear Controls Recursively I mean resting text to empty strings and removing UserControl from flowLayoutPannel

The Picture bellow the blue is a panel inside this I have TextBoxes, Labels, tabControl & groupboxes
Inside the groupboxes there are TextBoxes, Labels, and RichTextBox These need resetting back to Empty strings

the tabControl has FlowLayoutPanel with UserControl

This Code finds child controls but doesn't find the grandchildren

I'm aware  I should probably use a switch rather than if / else if but I can't call it recursively I get error  

The name 'ClearMoviePanel' does not exist in the current context

Open in new window


CODE

//  To Call
        ClrearMoviePanel(MoviePanel.Controls);

        public void ClrearMoviePanel(Control.ControlCollection controls)
        {
            foreach (Control control in controls)
            {
                foreach (Control child in control.Controls)
                {


                    if (child.Name == TitleTxtBox.Name)
                    {
                        continue;
                    }
                    else if (child is TextBox || child is Label || child is RichTextBox)
                    {
                        child.Text = string.Empty;
                    }
                    else if (child is FlowLayoutPanel)
                    {
                        child.Controls.Clear();
                    }
                    else if(child.HasChildren)
                    {
  

Open in new window

0
I have an old MVC project that I want to upgrade/port to ASP.Net Core Web Applications. I've been reading some articles:

Ex: https://arghya.xyz/articles/porting-aspnet-apps-to-aspnet-core-2.0/

I created an ASP.Net Web Application Core. I run it and I get the first page. I click on Login and takes me to the login page. But, I don't see the login page in the project.
I did a search and I don't see it. I clicked on "show all files" but still don't see it.

See screenshots below:

e1.png
e2.png
0
Hi Experts,
 We have some excel files in particular folder. Currently we create the dashboard from excel files. We manually open file ,  remove duplication, apply some filters and copy some cell value and update the dashboard. We have to do for all the files for each row for dashboard.

We would like to automation for this requirement. Can you please suggest me any tool/solution ?

Should we use .Net application or VBA code?
0
Hello Experts,

I 'm new to JQuery and using Datatable(3rd party o plug-in) to show data(grid style) on the page. Once the record is inserted I want to update the grid(new record is inserted via button click which opens modal popup and later I'm refreshing the grid). But I'm getting "Not available" when destroying the datatable so I rebuild it again with new data. Below is the sample code.

HTML
<div class="table-responsive m-t-40">

                    <table id="dataTable" class="display nowrap table  dataTable" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>First Name</th>
                                <th>Last Name</th>                               
                                <th>Phone</th>
                                <th>Email</th>                              
                            </tr>
                        </thead>
                        <tbody id="tblbody"></tbody>
                    </table>
                </div>

Open in new window


JavaScript
 $("#tblbody").empty();

                            data = JSON.parse(data);
                           $('#datatable').datatable().destroy(); -- Error here on  on Quick watch the value is "not available"
                            
                             -- Rest of the code doesn't execute due to error     
                            var html = '';
                            for (var i = 0; i < data.length; i++) {
                                var obj = data[i];

                                html += '<tr>'
                                html += '<td>' + obj.FirstName + '</td>';
                                html += '<td>' + obj.LastName + '</td>';                             
                                html += '<td>' + obj.PhoneNumber + '</td>';
                                html += '<td>' + obj.Email + '</td>';                                                                 
                                html += '</tr>'
                            }

Open in new window


If I comment $('#dataTable').DataTable().destroy() and try the above code I get a Warning message(popup) on the page and also tried $('#dataTable').DataTable().clear() it doesn't throw error but I got the same warning. Attached is the warning message.

Thanks,
ASPDEV
0
How to query or just get few columns a existing datatable to generate a new datatable of the result set.

Regards
0
This can't be that hard but I can't come up with a solution...

1. I have a datatable

Amount  LocId
------------  -------
1.00           STL
2.00           Laundry
4.00           STL
5.50           XYZ
9.00           STL
1.50           Laundry

2. This is what I want to do -->Add up the rows per "LocId" and insert into a table. So:

14.00      STL
3.5           Laundry
5.50         XYZ

3. I thought about looping and comparing LocId from one row to the next one. If same, add up. If not, move to the next row but then I think I have to do this for second row, third one, etc. Maybe somehow with LINQ?

Again, this can't be that hard.
0
Hello,
Given a date, how to get the date on Sunday for that week.
One line code will be great!

Thanks
0
Hello,

How can I find a count for many days remaining for a Sunday  in that week .
Example:
Date : 24/09/2019 which is Tuesday
The date on Sunday in that week  will be 29/09/2019
So the count is 5

I will be provided with the current date, need to find the remaining days count till Sunday.

Regards
0
Create a RESTful service (called News-API) using asp.net web api

TODO
● Create a Web-API .NET Core project for a RESTful service
● On startup, create a database by using EF Core (from nuget) containing the table “News”:
○ Id INTEGER PRIMARY KEY
○ Title VARCHAR(100) NOT NULL
○ Content text NULL
● Populate the table with a few dummy records (5 max)
● Add an API-Controller with the name “NewsController”
● Add an action to get all the records
● Add an action to get a specific record (primary key)
● Add an action to add a record
● Add an action to update a record
● Add an action to delete a record
0
I have the following piece of code

 <td style="cursor: auto; text-align: center" onmouseover="ShowAccount('vv<%# Eval("acct_nbr") %>','<%# Eval("acct_nbr") %>' );"
                                onmouseout="ShowAccount('vv<%# Eval("acct_nbr") %>','<%# Eval("acct_nbr_mask") %>' );">
                                <div id="vv<%# Eval("acct_nbr") %>">
                                    <asp:Label ID="lblAccountNbr" runat="server"><a href='AccountExceptionUpload.aspx'><%# Eval("acct_nbr_mask")%></a></asp:Label>
                                </div>
                            </td>

as you can see I am masking hte account number and on mouse hover you can see the account number. what I am trying to do is when i hover my mouse on account number i also want it converted to a hyper link . i tried putting <a> in the label but that did not help.
0
Building on previous  Questions  

I've been learning how to use ADO.NET Entity Data Model in a WinForms Using a movie Database I've included the model bellow

So far I've succeeded in doing select and updates I now need to add new data, Ultimately I'll need to add a new movie but that's to complex to start with

So Given File(s) can be associated with a movie via the   movielinkfile Database Table

How do I add a file and link it to a movie?

In SUDO code you'd
1 check file doesn't exists
2 Add the file.path Keep last ID
3 add entry to movielinkfile  with Last File ID & Movie ID

In .Net I'm assuming you create a File object see bellow but It doesn't like movie.id?

        private void AddFileBtn_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.InitialDirectory = MediaFiles;
            DialogResult dr = this.openFileDialog1.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                foreach (String file in openFileDialog1.FileNames)
                {
                    if (File.Exists(file))
                    {
                        int FileID = CheckFileDB(file);
                        if (FileID == 0)
                        {
                            AddFileToDB(SelectedMovieID, file);
                        }


                    }
                

Open in new window

0
How do you ensure a line of text has been selected?

In the mock up below on pressing the button a Line of text is written to a text box

However if no line has been actually selected IE user has not clicked in the RichTextBox the fist line is written

How do you ensure a user  has actually chosen a line?

Also a line of text could be longer then the RichTextBox width is it possible, on hover, to show the whole line in some kind of pop up label?  

BTW: In the Real App the lines in the RichTextBox will be file paths so using word wrap not really an option

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace TestForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
            richTextBox1.AllowDrop = true;
            richTextBox1.AutoWordSelection = false;

        }

        private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Rtf))
                e.Effect = DragDropEffects.Move;
            else
                e.Effect = DragDropEffects.None;
        }
        private void richTextBox1_DragDrop(object sender, 

Open in new window

0
I'm tripping over how to best accomplish this:

The Goal: to extract a block of data from a text file, using a line of fixed text as the
start and end markers, for the desired data.
The technology:  vb.net (2017) forms app

Example text of file:

ZZZZ 123455
RrtGGY 4454544

                    EEERTG
22212

                   ABCD
line of data#1
line of data#2
line of data#3
line of data#4

EFGH


In the above text, I'd like to parse the file, looking for "ABCD"
If found, then grab all lines of text between that, and:
"EFGH"

I've been trying  ReadAllLines method, but keep tripping over how to get what I'm wanting..

Thanks for any help.
Rich
0
I'm trying to work out how to drag and drop File(s) into a rich text box and grab file Path

The code bellow works however Why dose a file object also appear in the RichTextBox (This is related to which ever file your dragging, if more than 1 it's which ever you happen to of clicked on in Windows Explorer



FileDrop.JPG
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace TestForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //this.richTextBox1.AllowDrop = true;
            //this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);
            //this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragDrop);
            richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
            richTextBox1.AllowDrop = true;

        }

        private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Rtf))
                e.Effect = DragDropEffects.Move;
            else
                e.Effect = DragDropEffects.None;
        }
        private void richTextBox1_DragDrop(object sender, 

Open in new window

0
Hello,
If anyone knows  in Csharp,how to convert string such as "1.0.2" to decimal or double. I tried below but it gives error.

Convert.ToDecimal("1.0.2")

'Convert.ToDecimal("1.0.2")'
threw an exception of type 'System.FormatException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233033
    HelpLink: null
    InnerException: null
    Message: "Input string was not in a correct format."
    Source: "mscorlib"
    StackTrace: "   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\r\n   at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)\r\n   at System.Convert.ToDecimal(String value)"
    TargetSite: {Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)}
0
Hello,
In VB.NET  how can I get a date for the Monday in a week.
Example
Date selected is 17-09-2019 which is Tuesday , it should return 16-09-2019 which is Monday's Date
Date selected is 11-09-2019 which is Tuesday , it should return 09-09-2019 which is Monday's Date

Any suggestions?

Thanks
1
Hi

I have a movie database populated from TMDB api

On the main form each actor is generated by a User Control
Clicking the actors name sends both Actor Name and database person id to  People Search form
When I click the update button on the People Search form this should update the database

How do i update the UC on the main form?

Person search form
        private void PersonUpdateBTN_Click(object sender, EventArgs e)
        {
            using (var context = new MoviesEntities())
            {
                var results = context.people.SingleOrDefault(p => p.id == PersonID);
                if (results != null)
                {
                    results.name = ActorName;
                    results.tmdb_id = TMDB_id;
                    results.profile_path = profile_path;
                 //   context.SaveChanges();
                }
            }

        }

        private void OKbtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

Open in new window


Main Form
        private void GetCast(int id)
        {
            using (var context = new MoviesEntities())
            {
                var Movies =  context.movielinkpersons.Where(p => p.movieId == id).OrderBy(mp => mp.role) .ToList();
                foreach(var movielinkperson in Movies)
                {
                    var person = movielinkperson.person;
                    

                    var actorBox = new ActorBox(person);
                    

Open in new window

0
Hi

How do you orderBy ReleeseDate  when returning person Information from the TMDB API

This returns the Movie Credits but isn't ordered
                     TMDbClient client = new TMDbClient("API KEY");

                     public DateTime dateTime { get; set; }
            // Set Default Date
            dateTime = DateTime.Parse("01 / 01 / 0001");
                var PersonKnownFor = client.GetPersonMovieCreditsAsync(TMDB_id).Result;
                foreach(var PKF in PersonKnownFor.Cast)
                {
                    
                    if (PKF.ReleaseDate != null)
                    {
                        dateTime = DateTime.Parse(PKF.ReleaseDate.ToString());
                    }

                }

Open in new window



                var PersonKnownFor = client.GetPersonMovieCreditsAsync(TMDB_id).Result;
                foreach(var PKF in PersonKnownFor.Cast.OrderBy(PersonKnownFor.Cast.d)  // I think you order it here but can't see how
                 {
                    
                    if (PKF.ReleaseDate != null)
                    {
                        dateTime = DateTime.Parse(PKF.ReleaseDate.ToString());
                    }
                  int Year = dateTime.Year;
                

Open in new window


Also

Hovering over ReleaseDate suggests it is a System Date Time object but to get at the year I had to do above unsure why
0
In my windows forms application, I have a list of items <Container> which are populated into a datagridview. Each container has a unique ID. As follows:

ui1
In the datagridview, I have a "Modify" button column that when clicked, transfers the properties of the selected container onto the textbox controls in my UI. As follows:

ui2
Question: Given the above, how do I update the properties of a container within my list?

Background code:

Container class:

public class Container
    {
        #region Properties

        // Unique container ID
        public string ContainerID { get; set; }
        // Container description
        public string Description { get; set; }
        // Container payload capacity - weight
        public double CapacityWeight { get; set; }
        // Container payload capacity - cube
        public double CapacityCube { get; set; }
        
        #endregion  

        #region Constructor

        // Default constructor
        public Container()
        {
            ContainerID = Extension.NewID();
        }

        #endregion
    }

Open in new window


List initialization:

// Create an initial arbitrary list of containers to choose from
BindingList<Container> Containers = new BindingList<Container>();

Open in new window


private void initContainers()
        {
            // Add some containers to the container list
            Containers.Add(new Container() { Description = "20FT GENERAL PURPOSE", CapacityWeight = 23.4, CapacityCube = 30 });
            Containers.Add(new Container() { Description = "40FT GENERAL PURPOSE", CapacityWeight = 24.5, CapacityCube = 60 });
            Containers.Add(new Container() { Description = "40FT GENERAL PURPOSE - HIGH CUBE", CapacityWeight = 25.0, CapacityCube = 70 });
            Containers.Add(new Container() { Description = "US CHEP TWO-WAY PALLET", CapacityWeight = 1.524, CapacityCube = 1.8 });
        }

Open in new window

0
Hi

Using the TMDB API
I have a User Control on a winform with a TvTitleLbl Label & TvPosterPictureBox

I've been strangling to extract the year from KnownForTV.FirstAirDate having finally got it working, is this the best way?
I'm now getting Error, "Object reference not set to an instance of an object" on both the Label & PictureBox when trying to set it's properties unsure why ?

TvTit.jpg
the proper lable.text will be "TvTitleLbl.Text = "TV: " + pKFTV.Name + " ( " + year.ToString() + " )";"  shortened it to debug

KnownForTV.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MoviesDataModel;
using TMDbLib.Client;
using TMDbLib.Objects.General;
using TMDbLib.Objects.Movies;
using TMDbLib.Objects.TvShows;
using TMDbLib.Objects.Search;
using TMDbLib.Objects.People;

namespace FilmsDB
{
    public partial class KnownForTV : UserControl
    {
        TMDbClient client = new TMDbClient("API KEY");
        const string ImgPath = @"E:\Media\thumbs\Movies\";
        const string ImgURL = "https://image.tmdb.org/t/p/";
        const string OriginalImgPath = "http://image.tmdb.org/t/p/original";
        public string ThumbPhotoPath { get; set; }
        public string FullPhotoPath { get; set; }
        private KnownForTv pKFTV;



        public KnownForTV(KnownForTv pKFTV)

Open in new window

0

.NET Programming

134K

Solutions

39K

Contributors

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.