Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
E

ElSpinos

@ElSpinos
About
Posts
19
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • int is always 32-bit?
    E ElSpinos

    Just to add to the pot: The C# keyword int is a compiler accessor to the System.Int32 type. You may use the below code to validate this as an excercise on each platform:

    typeof(int) == typeof(System.Int32)

    The above code will return true.

    /F - .NET Developer

    C# question

  • How can i save event logs using C# ?
    E ElSpinos

    I don't believe the .NET Framework has native support for this, but you can try the following:

    // Declare this at the class member space
    [DllImport("advapi32.dll")]
    static extern IntPtr OpenEventLog(string lpUNCServerName, string lpSourceName);
    [DllImport("advapi32.dll")]
    static extern bool BackupEventLog(IntPtr hEventLog, string backupFile);

    // Somewhere in your code, call the above two declarations...
    // NOTE: Replace "localhost" with the machine name you need to back up.
    // Replace "Application" with the log you are trying to back up.
    // The saved file is an EVT file.
    BackupEventLog(OpenEventLog("localhost", "Application"), @"C:\TEMP\EVENTLOG.EVT");

    /F - .NET Developer

    C# question csharp

  • How to Update MDB file?
    E ElSpinos

    You will need to define the InsertCommand property of the DataAdapter like so:

    // Connection & DataAdapter initialization code should go here
    // ...

    OleDbCommand insertCommand = connection.CreateCommand();
    insertCommand.CommandText = "Insert Into Table(Col1, Col2, Col3) Values (?, ?, ?)";
    dataAdapter.InsertCommand = insertCommand;

    // ...

    You may also want to check out the UpdateCommand and DeleteCommand properties which will allow your adapter to update and delete records which is what it seems you are also trying to do in your code snippet.

    /F - .NET Developer

    C# question database tutorial announcement

  • how to validate Gridview cell's text .
    E ElSpinos

    You could try the following: 1 - Handle the DataGridView.EditingControlShowing event

    private void DataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
    // Make sure we're getting the key press event for a text type editor...
    if (e.Control.GetType() == typeof(DataGridViewTextBoxEditingControl))
    // Handle the editing control's keypress event...
    (e.Control).KeyPress += DataGridViewTextBoxEditingControlTextBoxControl_KeyPress;
    }

    2 - Inside the keypress event, check for the keys you need and process them

    private void DataGridViewTextBoxEditingControlTextBoxControl_KeyPress(object sender, KeyPressEventArgs e)
    {
    // Standard editing keys can be processed...
    if (e.KeyChar == (char)Keys.Back)
    {
    e.Handled = false;
    // No need for further validation...
    return;
    }

    // Just evaluate the contents of the cell if the value type is int
    // NOTE: _dataGridView here is a reference to the grid in context...
    if (_dataGridView.CurrentCell.ValueType != typeof (int))
    return;

    // Validate the key char...
    // NOTE: By specifying e.Handled = true, we are indicating that
    // we absorbed the character and this key is not sent to the cell.
    e.Handled = char.IsNumber(e.KeyChar);
    }

    Hope this helps...

    /F - .NET Developer

    modified on Wednesday, July 30, 2008 11:55 AM

    Windows Forms help css tutorial question

  • Asp.net Validation Controls are not working in Mozilla.
    E ElSpinos

    I experienced this issue some time ago and resolved it by installing the latest service pack of the .NET Framework. With my situation the validation control worked in IE but failed to do anything in Firefox. This was due to some javascript code which represents the validator at render time not being understood by firefox, the latest service pack makes changes to the validator's render code. Hope this helps...

    /F - .NET Developer

    ASP.NET csharp asp-net

  • Image Button in Datagrid
    E ElSpinos

    A possibility: Investigate using AJAX and embed an UpdatePanel in the EditItemTemplate containing the calendar with it's visible property set to false. When the image click event is fired, set the calendar's visible property to true to show the calendar. Good luck...

    /F - .NET Developer

    .NET (Core and Framework) tutorial question

  • How can i save event logs using C# ?
    E ElSpinos

    You could use the EventLog object to read the event log entries and then save them to a database or file, like so:

    // Opens the Application event log.
    EventLog eventLog = new EventLog("Application");
    // Iterate through the entries in the opened event log.
    foreach (EventLogEntry entry in eventLog.Entries)
    Console.WriteLine(entry.Message);

    /F - .NET Developer

    modified on Wednesday, July 30, 2008 10:23 AM

    C# question csharp

  • How to clear recent project entries from Visual Basic 2008
    E ElSpinos

    Try deleting the entries from this registry location:

    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\ProjectMRUList

    Fernando Mendes Senior .NET Developer, Architect

    Visual Studio csharp visual-studio windows-admin tutorial

  • How to insert data from MS SQL SERVER to MS Excell sheet?
    E ElSpinos

    Not the end solution but it will set you on the right track. Consider using the OleDbConnection object to open the excel spreadsheet. This will then allow you to execute T-SQL commands against spreadsheet as if it were a table.

    Fernando Mendes Senior .NET Developer, Architect

    Work Issues database sql-server sysadmin tutorial question

  • Global.asax issue
    E ElSpinos

    You could try to clear the error after you handle it in your ErrorLogger, like so:

    void Application\_Error(object sender, EventArgs e) 
    {
        Exception ex = Server.GetLastError().GetBaseException();
        string errStr = "Message: - " + ex.Message.ToString() + ", Source: - " + ex.Source.ToString();
        ErrorLogger.WriteErrorToFile(errStr);
    
        // Clear last exception...
        Server.ClearError();
    
        Response.Redirect("~/Error.aspx");
    }
    

    Fernando Mendes Senior .NET Developer, Architect

    ASP.NET help csharp sysadmin question

  • How to go to the next color?
    E ElSpinos

    Extending DaveyM69's advice, here's how you could go about getting the values you need:

    // Get all the property elements of the Color struct
    PropertyInfo[] PropertyInfo = typeof(Color).GetProperties();

    // Loop through the property info elements...
    foreach (PropertyInfo propertyElement in PropertyInfo)
    {
    // We're interested in color types...
    if (propertyElement.PropertyType == typeof(Color))
    {
    // propertyElement.Name will indicate the name of the colour, stick this into an array if needed...
    string colourName = propertyElement.Name;
    // Define a new Color type using the static FromName method to get the base colour value.
    Color c = Color.FromName(colourName );
    }
    }

    Fernando Mendes Senior .NET Developer, Architect

    C# question help tutorial

  • Converting Dataview to a Datatable.
    E ElSpinos

    Try this after applying the filter to the DataView: foreach (DataRowView rowView in dvUK) { dtChildUK.Rows.Add(rowView.Row); }

    Fernando Mendes Senior .NET Developer, Architect

    C# tutorial

  • Automating the double click required to resize a datagrids columns
    E ElSpinos

    Sometimes we try to think harder than the task at hand requires us to think. Grundyfoot's solution is much more practical... :)

    Fernando Mendes Senior .NET Developer, Architect

    C#

  • Automating the double click required to resize a datagrids columns
    E ElSpinos

    Hey Keith, There is a private method in the DataGrid control class that you can’t access directly through coding, however, all is not lost as Reflection can assist you here. I’ve done this before and implemented however I can’t find the souce I used so here is a brain dump from what I can remember:

     // You'd probably want to do this every time the data grid changes it's data
     // so implement the DataSourceChanged event...
     private void MyDataGrid_DataSourceChanged(object sender, System.EventArgs e)
     {
      try
      {
       // First lets get the assembly's type reference...
       Type assemblyType = MyDataGrid.GetType();
       // The DataGrid has a method called ColAutoResize (declared as private and no-one knows why)
       // We can invoke this by getting a reference to it in the MethodInfo class.
       MethodInfo methodInfo = assemblyType.GetMethod("ColAutoResize", BindingFlags.NonPublic);
    
       // Iterate through your columns...
       for (int i = MyDataGrid.FirstVisibleColumn; (i < MyDataGrid.VisibleColumnCount); i++)
       {
        // Invoke the ColAutoResize method, the method expects a single integer
        // column index as the parameter, so we’ll pass I as an argument in the
        // object[] array.
        methodInfo.Invoke(MyDataGrid, new object[] { i });
       }
      }
      catch (Exception ex)
      {
       // Something went horribly wrong, examine the exception and deal 
       // with it accordingly or just simply ignore it, this shouldn’t 
       // happen anyhow...
      }
     }
    

    I hope this gets you furthur in your project, happy reflectioning! :)

    Fernando Mendes Senior .NET Developer, Architect

    C#

  • Runtime Web Service Invocation
    E ElSpinos

    Hey there MrEyes, You’ve been posed with a tough one there and you might have to do some research on the following topic: Reflection and runtime target invocation. In a nut shell, you will need to implement the following strategy in your proxy assembly: * You will need to create a public interface that all your web services must implement. The reason being that your proxy will need this metadata to expose the underlying functionality to the caller and identify the service as a deployable package. * You will need to implement a directory search service that looks for new web services and checks for the presence of the public interface you implemented above. Store the value away in a file or database so that you have a list of web services you know about. * Through runtime target invocation, you can now call the web service functionality dynamically; you will need knowledge of the Reflection namespace to achieve your goal. I hope I’ve pointed you in the right direction for now, good luck. :)

    Fernando Mendes Senior .NET Developer, Architect

    C# question wcf business

  • gridview to database
    E ElSpinos

    Hi there sangramkp, From what i understand in your requirement is that you want to take the values from an already populated GridView control and insert the last three columns into a table called tblSlab. You will need to iterate through the GridView's Rows property and extract the cells by index since you know which ones you need, consider the following code:

      foreach (GridViewRow row in GridView.Rows)
      {
       // You indicated you wanted the last three cells...
       // Note that the cells collection is zero based...
       sqlScript = "Insert Into tblSlab Values(" + row.Cells[1].Text + ", " + row.Cells[2].Text + ", " + row.Cells[3].Text + ", ";
       // Now execute your code to insert the record into your table...
      }
    

    And thats it... Have fun! :) -- modified at 6:18 Friday 14th September, 2007

    Fernando Mendes Senior .NET Developer, Architect

    ASP.NET database tutorial

  • Gridview Paging and Sorting
    E ElSpinos

    Greetings satishkumarnk, You will need to implement the following two events:

    1 - PageIndexChanging
    protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { // This line tells the grid which page to go to // Have a look at the GridViewPageEventArgs object // to get more insight on what information it contains. GridView.PageIndex = e.NewPageIndex; // Simply rebind your grid. GridView.DataBind(); }
    2 - Sorting
    protected void GridView_Sorting(object sender, GridViewSortEventArgs e) { // We will append this string later with the direction // for now lest just add the column name the user clicked on string sqlScript = "Select * From MyTable Order By " + e.SortExpression; // Test for the direction... if (e.SortDirection == SortDirection.Ascending) { // Append the ASC keyword to your script sqlScript += " ASC"; } else { // The SortDirection enumeration is binary so an else block will suffice sqlScript += " DESC"; } // Rerun your sql script to retrieve the newly sorted data... // bind the gridview GridView.DataBind(); }

    And thats it... Happy implementing! :)

    Fernando Mendes Senior .NET Developer, Architect

    ASP.NET wpf wcf design algorithms question

  • singleton pattern example
    E ElSpinos

    Greetings Shakeela, The Singleton design pattern serves to describe an implementation that restricts instantiation of a class to one object, in other words no copies or additional references. I've created a Singleton instantiate for you here to experiment with and get an idea of my description above. the singleton design pattern also belongs to the Creational Patterns group which consist of the following additional design patterns: o Abstract factory pattern: centralize decision of what factory to instantiate o Factory method pattern: centralize creation of an object of a specific type choosing one of several implementations o Builder pattern: separate the construction of a complex object from its representation so that the same construction process can create different representations o Lazy initialization pattern: tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed o Object pool: avoid expensive acquisition and release of resources by recycling objects that are no longer in use o Prototype pattern: used when the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword) is prohibitively expensive for a given application The singleton class you can experiment with: /// Any type with a public and parameterless constructor. public sealed class SingletonCreator where Type : class, new() { #region Private declarations /// /// The instance to retain after creation /// private static Type instance; #endregion #region Properties /// /// A lazy instance instantiator property. It will test for the existence of an object and return that reference otherwise it will create a new object. /// /// An singleton instance of type "Type". public static Type GetInstance() { lock (typeof(Type)) { if (instance == null) { instance = new Type(); } return instance; } } #endregion } Usage: // This will always create an instance it it doesn’t exist or return the // existin reference if it was previously called. MyClass myClass = SingletonCreator<MyClass>.GetInstance(); I hope this helps you in your quest to learn design patterns ;) Have an awesome weekend...

    Fernando Mendes Senior .NET Developer, Architect

    Design and Architecture design regex architecture tutorial

  • Iterarting menu item
    E ElSpinos

    Greetings Amar, If you look at how the MenuStrip control works you will notice that it houses a different type of collection, the ToolStripItemCollection in its MenuStrip.Items property. You need to iterate each ToolStripMenuItem in that collection to get its children. After that, the ToolStripMenuItem has another ToolStripItemCollection in it's DropDownItems property, you now need to iterate through this collection to get it's children and so forth... consider the following example: void ListControls(Control parentControl) { foreach (Control control in parentControl.Controls) { MessageBox.Show("Control Type : " + control.GetType().ToString() + "\n" + "Has Children : " + (control.Controls.Count > 0 ? "Yes" : "No") + "\n"); // Perform the child-find functionality on the ControlCollection here. if (control.Controls.Count > 0) { // Call ourselves to discover additional children... this.ListControls(control); } // Get the sub menus of a MenuStrip. // * Test for the type of control, we're looking for the MenuStrip here... // TODO: Add this to a different function to nest-find child tool strips. if (control.GetType() == typeof(MenuStrip)) { // As you can see, the menu houses a collection of items not controls, notice this is now a ToolStripItemcollection not ControlCollection. foreach (ToolStripMenuItem toolStripMenuItem in ((MenuStrip)control).Items) { MessageBox.Show("---> Menu Strip '" + ((MenuStrip)control).Text + "' has '" + toolStripMenuItem.Text + "' as a child item."); // Test if tool strip has child items, notice this is a ToolStripItemcollection too. if (toolStripMenuItem.DropDownItems.Count > 0) { // Call your nested-find function... } } } } } Basically, the MenuStrip needs to be treated like a TreeView as it can contain a complex hierarchy. I hope this helps... Have a great weekend!

    Fernando Mendes Senior .NET Developer, Architect

    C# data-structures
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups