Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

C#

92K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

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

Sign up to Post

I would first describe what I am trying to do to explain my question.
I have custom class in my Project called Book with two properties - a Title and an Author (both strings).

I have a Command Button (named simpleButton)on a Form in my VBA application. I would like to assign an instance of this Book class (myBook) to the simpleButton (in some way). In my code I am assigning the tag property of simpleButton the value of myBook
I would now like the caption of this simpleButton to be equal to the Title of myBook (which in a previous line has been assigned to the tag property of simepleButton.
(I can do this kind of thing using C sharp in a .NET application Windows application and I trying to do the same in VBA). The code I have put in the code window may not make complete sense, but will hopefull explain my intention.
Private Sub cmdSimple_Click()

Dim myBook As book
myBook .Title = "Emma"
myBook .Author = "Jane Auston"
Me.cmdSimple.Tag = myBook 
 Object obj = Me.cmdSimple.Tag

 ' I basically want to cast obj to Book in the line that follows
  myBook = obj as book
  
Me.cmdSimple.Caption = myBook .Title

End Sub

Open in new window

0
Important Lessons on Recovering from Petya
LVL 10
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

A quick helper class to issue a manual SOAP Web Service request without using WSDL, proxy or SoapClient using C# using ASP.NET 2.x, 3.x, 4.x or .NET Core.
0
New to GDI and BitBlt. Have a need for a high speed display of data that can go on for days (lots of data to pass through the screen). Using BitBlt so that I am not redrawing the entire screen data every update, only the part that has changed. I am using the following code just to test synthetic data, the timer is set to every 5ms (not needed but testing the code), new data is added to the right of the screen and find that I run into an 'Out of memory exception in System.Drawing'. Can anyone see what I am not releasing in the following code?

 private void MoveDisplay(object sender, EventArgs e)
        {
            //find the width and height of the canvas (the picture box)
            int w = pictureBox1.Size.Width;
            int h = pictureBox1.Size.Height;

            //grab the current image
            Bitmap bsrc = (Bitmap)pictureBox1.Image;

            //create a new bitmap basd on the size we need
            Bitmap bdst = new Bitmap(w, h);

            //create a source graphics context
            System.Drawing.Graphics gsrc = pictureBox1.CreateGraphics();

            //create a destination graphics context
            System.Drawing.Graphics gdst = System.Drawing.Graphics.FromImage(bdst);

            //get the handles to the source and destination contexts
            IntPtr dcsrc = gsrc.GetHdc();
            IntPtr dcdst = gdst.GetHdc();          

            //blit the source context to the destination context starting 
            //1 pixel 

Open in new window

0
Hello Experts,

I got a page with a gridview.  want to delete the row, so I click the delete button on the row.

I am seeing this error and banging my head.
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
                     TableCell cell = GridView1.Rows[e.RowIndex].Cells[1];

                     _process.DeleteAttachmentByID(Convert.ToInt32(cell.Text));
                    
                 
        }

----**************************************---------


 public void DeleteAttachmentByID(int AttachmentID)
        {

            var reqAttach = GetRequestAttachmentByID(4);

            RequestAttachmentRepository rep = new RequestAttachmentRepository();            

            rep.DeleteEntity(reqAttach);
        }


_*************************************************--

 public void DeleteEntity(T entity)
        {
            Context.Entry<T>(entity).State = EntityState.Deleted;
            Context.SaveChanges();
        }

        

Open in new window



-- Dan
0
I had this question after viewing Need some advice on how to create a program that can draw data model?.

Thank you for providing such wonderful solution appreaciated.
I have two  requirement changes  :
1) to use tree view instead of list boxes.
2) save the connections and bring it up after you close and reopen the form
Can you please post the code for the same
Thanks for your help in advance
0
using c#, is it possible to find all
assume i have xml file with over 1000 nodes below. I want to get the list of attitrbute called ID.
but I won't know where is the root. like tests or test.

I basically just want to loop xml to find all of the ID name, and then find t he element name.
once i get element name, then i want to fill in the value <ans>got it</ans>


and i
<tests>
<test id="id_name1">
   <ans id=id_ans1"></ans>
</test>
</test>
<test id="id_name2">
   <ans id=id_ans2"></ans></test>
</test>


</tests>
0
I have xml below, and If i just give you  'applicantFirstName' and the value is 'John'
how can we add
'John' into       <FirstName ID="applicantFirstName" PrefillValue="No">John</FirstName>?

based on two requirements

1. I will only pass you  Dictionary<string, string> e.g. <applicantFirstName,'john'>
2. You actually do not know the structure of xml except you know each element has "ID" attritbute. meaning that you pass 'applicantFfirstName'' only into xml, and try to find element, and add value (John) there.

so you won't be able to use linq like doc.Descendants("Applicant").FirstOrDefault()

Let me know if this is possible.

<Surety>
  <SuretyLine>
    <Commercial>
      <Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">Contractor</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>
          
          <Code PrefillValue="Yes">888</Code>
          <Renew PrefillValue="Yes">
            <Year>1</Year>
          </Renew>
        </GeneralInformation>
        <Coverage>
          <Amount PrefillValue="Yes">15000</Amount>
          <Year PrefillValue="Yes">1</Year>
        </Coverage>
        <Applicant>
          <CompanyName ID="applicantCompanyName" PrefillValue="No"></CompanyName>
          <CompanyEntityType ID="applicantCompanyEntityType" PrefillValue="No"></CompanyEntityType>
          <CompanyTaxID ID="applicantCompanyTaxID"></CompanyTaxID>
          <FirstName 

Open in new window

0
get alert on line if (elementID == update.Key) because update.key is string.
how can i fix it?

       
 public void CreateQuoteFile(Dictionary<string, string> changes)
        {
            string fileName = CreateXmlfile("License","CA");
            XDocument doc = XDocument.Load(fileCreateQuotePath+fileName);
            foreach (var update in changes)
            {
                var element = doc.Descendants(update.Key).FirstOrDefault(); //element from XML file
                var elementID = doc.Descendants(update.Key).Select(b=>b.Attribute("ID")).FirstOrDefault(); //element ID from XML file

                //if (elementID != null) 
                if (elementID == update.Key)
                {
                    element.Value = update.Value;
                }
            }
            string fileNameNew = Guid.NewGuid().ToString() + ".xml";
            doc.Save(fileCreateQuotePath + fileNameNew)

Open in new window

;
0
Below codes is reading my xml Applicant
and try to find Element e.g. CompanyName (var element = doc.Descendants(update.Key).FirstOrDefault();)
But I try to find ID, how can i do that?
My goal is to find ID
like applicantCompanyName = update.value


public void CreateQuoteFile(Dictionary<string, string> changes)
        {
            string fileName = CreateXmlfile("CA");
            XDocument doc = XDocument.Load(fileCreateQuotePath+fileName);
            foreach (var update in changes)
            {
                var element = doc.Descendants(update.Key).FirstOrDefault();
                if (element != null)
                {
                    element.Value = update.Value;
                }
            }

            string fileNameNew = Guid.NewGuid().ToString() + ".xml";
            doc.Save(fileCreateQuotePath + fileNameNew);            
        }



<Applicant>
<CompanyName PrefillValue="No" ID="applicantCompanyName"/>
<CompanyEntityType PrefillValue="No" ID="applicantCompanyEntityType"/>
<CompanyTaxID ID="applicantCompanyTaxID"/>
<FirstName PrefillValue="No" ID="applicantFirstName">asdfasdf</FirstName>
<LastName PrefillValue="No" ID="applicantLastName"/>
<MiddleName PrefillValue="No" ID="applicantMiddleName"/>
<StreetName PrefillValue="No" ID="applicantStreetName"/>
<City PrefillValue="No" ID="applicantCity"/>
<State PrefillValue="No" ID="applicantState"/>
<Zip PrefillValue="No" ID="applicantZip"/>
<PhoneNo PrefillValue="No" …
0
when the onchange is occurred,
how can i send the selected value to the controller for other processing?
<select class="select2" id="bondState" name="bondState" onchange="fnSaveSingleData(this.name,'1')" data-placeholder="Choose Bond State...">
                                    <option value=""></option>
                                    @foreach (var item in Model.stateList)
                                    {
                                        <option value=@item>@item</option>
                                    } 
                                </select>

Open in new window

0
Ask an Anonymous Question!
LVL 10
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Can you please tell me why I am getting this error? I copied some projects from a different computer but I am getting error  in database connectivity.
screenshot.png
0
I'm using ASP.NET MVC 4 and LINQ/SQL. I have an HTML page with a form where I want to render HTML input boxes based on a Model Class. In my view, I'm looping over the model and trying to generate an input box for each table row, but since the model is empty, the input boxes do not show. The model is empty because there is no data in the database yet as that is what I want to collect in my form. When there is data in the model, the values from the database should show in the form.

How can I render the empty input boxes, given that my model is initially empty.

Code is below:

@for (int i = 0; i < Model.Count; i++)
    {  
 <tr>

    <td>                           
      @Html.EditorFor(model => model[i].CustomerName, new { htmlAttributes = new { @class = "form-control" } })
    </td>

 </tr>
 }

Open in new window

0
I am receiving the below error.
System.InvalidOperationException was unhandled
  Message="An error occurred creating the form. See Exception.InnerException for details.  The error is: The type initializer for 'MyProject.Singleton' threw an exception."
  Source="Prj - MyProject"
  StackTrace:
       at MyProject.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
       at MyProject.My.MyProject.MyForms.get_F_Login()
       at MyProject.My.MyApplication.OnCreateMainForm() in C:\Users\xxxxxxxx\Documents\Source_MyProject\Prj-MyProject\Prj\My Project\Application.Designer.vb:line 35
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at MyProject.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.TypeInitializationException
       Message="The type initializer for 'MyProject.Singleton' 

Open in new window

0
How do you load an Excel file into a DataSet using C#?

Thanks,

Dan Lorenz
0
Hey all,

I have an application that is being used for many clients. However, I've been asked to consolidate to a single code base. The application is also in need of a nice face lift to become more aesthetically pleasing as well as to increase the over all UI/UX. I've never event attempted something like this before so my question is: Would it best to develop/re-develop in C#/MVC or WebForms or modify the current VB.NET application to utilize new features etc.? All of the clients have a similar type of service, however, there are some drastic differences to features, the display of information etc. That being said, I'm not too sure of how cost effective it would be to attempt to consolidate into a single code base vs redeveloping the application utilizing as much code as possible with translation into C#.
0
The folder is located in the network \\rst\dept\detail\.  Before a batch program in the task scheduler executes,
I'd like to test it first if a file with .pdf exists. if none, sends a message on screen "No input files"
0
Thank you fo spending time read my post!
This is project with .sln file https://drive.google.com/open?id=0BwnB8SavOtQPZndIdjJUZExpNXM
I tried many times and ask so many help to solve this. But after publish application-> setup -> run application (issue at this step)
Nothing happend when i run application.
I see on task manager: my app appear but immediate suspended.
Please help. I got stuck it a month :( :( :(
0
when the onchange is occurred,
how can i send the selected value to the controller for other processing?


<select class="select2" id="bondState" name="bondState" onchange="fnSaveSingleData(this.name,'1')" data-placeholder="Choose Bond State...">
                                    <option value=""></option>
                                    @foreach (var item in Model.stateList)
                                    {
                                        <option value=@item>@item</option>
                                    } 
                                </select>

Open in new window

0
in bond.bondnamelist - how can i capture the selected state (e.g. CA)
and make bond.bondnamelist like (if CA is selected, the bondnamelist value will be {"CA Product"}? I want to do that on controller codes behind. not razor



public ActionResult BondInfo(Model.Bond bond)
        {
            bond.stateList = new List<string> { "CA", "FL", "TX" };
            bond.bondNameList = new List<string> { "CA Product", "FL Product", "TX Product" };
            return View(bond);
        }

<select class="select2" id="bondState" name="bondState" onchange="fnSaveSingleData(this.name,'1')" data-placeholder="Choose Bond State...">
                                    <option value=""></option>
                                    @foreach (var item in Model.stateList)
                                    {
                                        <option value=@item>@item</option>
                                    } 
                                </select>


<select class="select2" onchange="fnSaveSingleData('bondName','0')" id="bondName" name="bondName" data-placeholder="Choose bond name(s)...">
                                    <option value=""></option>
                                    @foreach (var item in Model.bondNameList)
                                    {
                                        <option value=@item>@item</option>
                                    }                                     
                                </select>



js:

Open in new window

0
Concerto's Cloud Advisory Services
LVL 4
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Below is MVC project, and how can I pass the state list value into cshtml?


 public ActionResult Index()
        {
            return View(StateList());
        }


 private List<string> StateList()
        {
            List<string> str = new List<string>();
            XElement xelement = XElement.Load(fileBondList);
            foreach (XElement xEle in xelement.Descendants("State"))
            {
                str.Add((string)xEle);
            }
            return str;
        }

Open in new window

0
<Surety>
<SuretyLine>
<Commercial>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">C</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">Z</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">B</Name>
          <State ID="bondState" PrefillValue="Yes">FL</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
</Commercial>
</SuretyLine>
</Surety>

Open in new window


Above XML, if I give you Element Name Value = 'B' and State = "FL" and try to get the xml string and save into result.xml. How can I do that?


My end result should look like below:

<Surety>
<SuretyLine>
<Commercial>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">B</Name>
          <State ID="bondState" PrefillValue="Yes">FL</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
</Commercial>
</SuretyLine>
</Surety> 

Open in new window

0
Hi All,

i want to achieve above feature.

How could I do it ?

Thank you,
0
1. How can get the list (element (State)))  filter by state if parameter is given e.g. (CA) order by State asc?
2. How can get the list (element (Name)) filter by Status = Online and state = "CA" order by Name asc?

3. How can get total count of Bond filer by state?
4. How can get total count of Bond filter by Status (e.g. Online)?

I would like to see in c#.

Thanks,


<Surety>
<SuretyLine>
<Commercial>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">C</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">Z</Name>
          <State ID="bondState" PrefillValue="Yes">CA</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
<Bond>
        <GeneralInformation UI="BondInfo">
          <Name ID="bondName" PrefillValue="Yes">B</Name>
          <State ID="bondState" PrefillValue="Yes">FL</State>         
        </GeneralInformation>              
        <Status>Online</Status>
</Bond>
</Commercial>
</SuretyLine>
</Surety>

Open in new window

0
I'm wanting to show a .gif while some processing goes on in the background, but I'm not able to get it to show, not even sure if it will 'animate', but I'm gonna hope for the best, once I can get it to show.

In my master page I have this:

    <style type="text/css">
        .lnkBtnTFBlue {
            display: none;
        }

        .LockOff {
            display: none;
            visibility: hidden;
        }

        .LockOn {
            font: arial;
            font-size: xx-large;
            font-weight: bolder;
            display: block;
            visibility: visible;
            position: absolute;
            z-index: 50000;
            top: 0px;
            left: 0px;
            width: 105%;
            height: 105%;
            background-color: #CCC;
            text-align: center;
            padding-top: 20%;
            filter: alpha(opacity=75);
            opacity: 1.5;
        }
    </style>

    <script type="text/javascript">
        $(document).ready(function (jQuery) {
            function LockScreen(str) {
                var lock = document.getElementById('LockPane');
                if (lock)
                    lock.className = 'LockOn';

                if (str != '') {
                    lock.innerHTML = str;
                }
            }
        });
</script>
.
.
.
    </form>
    <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="js/response.min.js"></script>
    

Open in new window

0
How to check which element is clicked? I need to know if the user clicked on a link or not
0

C#

92K

Solutions

25K

Contributors

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).