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
S

Stanciu Vlad

@Stanciu Vlad
About
Posts
250
Topics
28
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Combo Box value set problem
    S Stanciu Vlad

    I think that using comboBox1.Items.Clear(); is not a correct thing to do (it messes up all you selected items and so on). All your code can be replaced (if you use .net 2 or greater) with the functionality of the autocomplete[^] feature.

    I have no smart signature yet...

    C# csharp help

  • A gem.
    S Stanciu Vlad

    It would have been a gem if the code was something like this:

    "argument1;argument2;argument3".Split(";".ToString());

    :-D

    I have no smart signature yet...

    The Weird and The Wonderful ruby

  • What did he want to lock?
    S Stanciu Vlad

    Maybe he was afraid that someone/something (like Windows, CLR or even God) would change his path containing local string before he got to delete the file. :) Does that count as paranoia? :-D

    I have no smart signature yet...

    The Weird and The Wonderful csharp question

  • how about erasing trace of Rectangle? [modified]
    S Stanciu Vlad

    Of course there are other methods. For example you could: 1) get the image residing in the place you drawed your first rectangle 2) put the image over the first rectangle 3) get the image residing in the place you want to draw the second rectangle 4) draw the second rectangle 5) and so on Basicly, instead of filling with white the place where was the old rectangle, you could fill it with the old image data. Or, if you are really lazy, you could paint the background image over the whole control in order to remove the old rectangle and maintain the background. PS: be carefull of performance issues, drawing an image at every 20 ms it is not a good way to waste cpu time.

    I have no smart signature yet...

    C# csharp wpf graphics linq com

  • Unhandled exception in the designer (OnPaint)
    S Stanciu Vlad

    I think that your control must be able to function even if it's not binded to data. Make it display something on it to inform you that there is no data binded (like a big red text "NO DATA BINDED" :)). This sould be easy if you say that you do the painting.

    I have no smart signature yet...

    C# design question

  • how about erasing trace of Rectangle? [modified]
    S Stanciu Vlad

    How about erasing the old rectangle before drawing a new one?

    System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red, 5);
    System.Drawing.Pen whitePen = new System.Drawing.Pen(System.Drawing.Color.White, 5); // define the erasing pen
    g.DrawRectangle(whitePen, myRec); // erase the old rectangle
    myRec.Width = (int)width; // adjunst the new rectangle coordinates
    myRec.Height = (int)height;
    g.DrawRectangle(myPen, myRec); // draw the new rectangle
    InvalidateVisual();

    I have no smart signature yet...

    C# csharp wpf graphics linq com

  • Help required in Threading..
    S Stanciu Vlad

    Synchronization in multithreading environments can be done with semaphores[^] and mutexes[^]. Here[^] is a mutex example.

    I have no smart signature yet...

    C# hardware sales help question

  • datagridview filtering....where to start?
    S Stanciu Vlad

    I don't recall, but if in certain conditions you get an exception then you've found a bug :)

    I have no smart signature yet...

    C# question help

  • datagridview filtering....where to start?
    S Stanciu Vlad

    It's ok if it works. I's kind of based on the principle stated by me in a previous post. The filter logic is a little diferent, it's a different approach. Just as a note: 1. a bindingSource does aproximatively the same thing as a dataView (if not the same), so there is no reason to bind to the bindingSource a dataView binded to a dataTable. You could bind the table directly to the bindingSource. 2. having a filtered and an unfiltered bindingSource is the same as having a bindingSource that can be filtered or unfiltered. :) 3. I think that if you change the datasource of a control the current selected value is lost (not sure, but this would seam logic to me)

    I have no smart signature yet...

    C# question help

  • datagridview filtering....where to start?
    S Stanciu Vlad

    mainData is the place where the data is stored. I said that you could persist this in a database. So if you did that then your table would look like that: with a reference to the ValueType table and a referece to the ValueUnitOfMeasurement on each row. If you comment out all the mainData columns you would not have a place where to store the data entered in the grid and the grid would be empty. So, if you add different types of measurements and do not bind them correctly the application will crash. In all the tables the ID column must be unique (numbers from 1 to n). In the valueUnitOfMeasurement table there is an ID column (that must be unique) and a reference to a valueType (stated in the valueType table). The reference is the ID of the valueType. Let's assume you want to add a new measurement type named "Distance" with the units of measurement "km", "m", "cm", "mm". The first step is to add the record in the ValueType table:

    valueType.Rows.Add(new object[] {100, "Distance"});

    Note that the row added is [100, "Distance"] - 100 is the Distance's ID (must be unique in the table). Next you must add records in the ValueUnitOfMeasurement table:

    valueType.Rows.Add(new object[] {500, 100, "km"});
    valueUnitOfMeasurement.Rows.Add(new object[] {501, 100, "m"});
    valueUnitOfMeasurement.Rows.Add(new object[] {502, 100, "cm"});
    valueUnitOfMeasurement.Rows.Add(new object[] {503, 100, "mm"});

    Note that the first row added is [500, 100, "km"] - 500 is the UnitOfMeasurement's ID and 100 is the valueType's ID correspondind to this unit of measurement (A couple of lines above we stated that for distance 100 is the ID). The logic in my previous example filters the unit of measurements based on the selected value type ID in the valueType combo box. This supports an logically unlimited number of measurement types and units of measure. Also this supports persistance (database or xml).

    I have no smart signature yet...

    C# question help

  • datagridview filtering....where to start?
    S Stanciu Vlad

    Check this out...

        private void Form1\_Load(object sender, EventArgs e)
        {
            DataTable mainData = new DataTable("mainData");
            mainData.Columns.Add("ID", typeof(int));
            mainData.Columns.Add("ValueType", typeof(int));
            mainData.Columns.Add("ValueUnitOfMeasurement", typeof(int));
            mainData.Columns.Add("TheValue", typeof(decimal));
    
            DataTable valueType = new DataTable("valueType");
            valueType.Columns.Add("ID", typeof(int)); // should be like a primary key
            valueType.Columns.Add("Description", typeof(string));
    
            DataTable valueUnitOfMeasurement = new DataTable("valueUnitOfMeasurement");
            valueUnitOfMeasurement.Columns.Add("ID", typeof(int)); // should be like a primary key
            valueUnitOfMeasurement.Columns.Add("ValueTypeID", typeof(int));
            valueUnitOfMeasurement.Columns.Add("Description", typeof(string));
    
            valueType.Rows.Add(new object\[\] { 1, "Force" });
            valueType.Rows.Add(new object\[\] { 2, "Torque" });
            valueType.Rows.Add(new object\[\] { 3, "Pressure" });
    
            valueUnitOfMeasurement.Rows.Add(new object\[\] { 1, 1, "lb"});
            valueUnitOfMeasurement.Rows.Add(new object\[\] { 2, 1, "N" });
            valueUnitOfMeasurement.Rows.Add(new object\[\] { 3, 2, "N-m" });
            valueUnitOfMeasurement.Rows.Add(new object\[\] { 4, 2, "in-lb" });
            valueUnitOfMeasurement.Rows.Add(new object\[\] { 5, 3, "Pa" });
            valueUnitOfMeasurement.Rows.Add(new object\[\] { 6, 3, "bar" });
    
    
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = mainData;
    
            valueTypeColumn.DataSource = valueType;
            valueTypeColumn.ValueMember = "ID";
            valueTypeColumn.DisplayMember = "Description";
    
            myBinding.DataSource = valueUnitOfMeasurement;
            valueUnitOfMeasurementColumn.DataSource = myBinding;
            valueUnitOfMeasurementColumn.ValueMember = "ID";
            valueUnitOfMeasurementColumn.DisplayMember = "Description";
    
            dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1\_EditingControlShowing);
            dataGridView1.RowValidated += new DataGridViewCellEventHandler(dataGridView1\_RowValidated);
        }
    
        void dataGridView1\_RowValidated(object sender, DataGridViewCellEventArgs e)
        {
            myBinding.Filter = string.Emp
    
    C# question help

  • datagridview filtering....where to start?
    S Stanciu Vlad

    BindingSource secondTableBindingSource = new BindingSource();
    public void Form1_Load(object sender, EventArgs e) {
    // ... etc

    DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
    col.DataSource = tblPrimary;
    col.ValueMember = "Type";
    dataGridView1.Columns.Add(col);
    
    **secondTableBindingSource.DataSource = tblSecondary;**
    
    DataGridViewComboBoxColumn col2 = new DataGridViewComboBoxColumn();
    **col2.DataSource = secondTableBindingSource;**
    col2.ValueMember = "Unit";
    dataGridView1.Columns.Add(col2);
    

    }

    private void primaryCB_SelectedIndexChanged(object sender, EventArgs e)
    {
    if (dataGridView1.CurrentCell.ColumnIndex == 0)
    //allow control on only one column
    {
    ComboBox cb = sender as ComboBox;
    if (cb != null)
    {
    if(cb.SelectedValue != null)
    secondTableBindingSource.Filter = string.Format("Primary_Type = '{0}'", cb.SelectedValue);
    else
    secondTableBindingSource.Filter = string.Empty;

    }
    }
    }

    I have no smart signature yet...

    C# question help

  • A function that does... nothing... :-).
    S Stanciu Vlad

    Is that function used inside the application or it was created just for a better and larger number of lines?

    I have no smart signature yet...

    The Weird and The Wonderful announcement

  • datagridview filtering....where to start?
    S Stanciu Vlad

    You can use BindingSource to bind a dataTable to almost any control.

    BindingSource bsOrders = new BindingSource();
    bsOrders.DataSource = Dataset1;
    bsOrders.DataMember = "Orders"

    Bind the comboBoxColumn in the gridview to this binding source (if you don't know how check google, it's full of this stuff) Then in the comboBox SelectedIndexChanged event you can directly filter the data using

    //eventualy do a nothing selected check
    if(filterText == string.Empty)
    bsOrders.Filter = string.Empty;
    else
    bsOrders.Filter = "Option1 = " + filterText;

    I have no smart signature yet...

    C# question help

  • Logical genius!
    S Stanciu Vlad

    Simone Serponi wrote:

    And notice the lack of argument value check before using iHandle in IsUsed() function

    Who needs to check the argument for a valid range? :confused: Hey, it's not my fault if you don't know how to properly use a function :laugh:

    I have no smart signature yet...

    The Weird and The Wonderful code-review

  • partition clone with c#
    S Stanciu Vlad

    Clonning a partition is not an easy task, and by far an easy one to do with managed code. If you want to do a full clone then your aim is to understand partition descriptors, file and folder descriptors and all the stuff that goes behind a file system when it acceses a partition. Why it is necessary to understand them, simple you can't just rely on the file system of an os and there are lots of existing partition types. If you want just to copy all the files from a partition to another you must keep in mind that critical files opened by the operating system and/or applications are not readeable (nor writable) unless they are closed (or opened under special conditions). ps: partition != hard drive :)

    I have no smart signature yet...

    C# csharp help question

  • How to disable event handler from its execution
    S Stanciu Vlad

    How about using a flag in order to suppres the event?

    private bool suppresEvent = false;
    private void button1_Click(object sender, EventArgs e)
    {
    if(suppresEvent)
    return;

    suppresEvent = true;

    // do your hard work here
    System.Threading.Thread.Sleep(3000);

    suppresEvent = false;
    }

    I have no smart signature yet...

    C# csharp help tutorial question

  • Date Pickers with Checkboxes and Modified Rows
    S Stanciu Vlad

    Check the DaraRow.DataRowState property. Also, if you want a list with all the changes you could call DataTable.GetChanges. Check MSDN for those properties. Note that those properties are not static, they must be called upon an instance.

    I have no smart signature yet...

    C# question database debugging

  • SQL server name not found:Admin-PC\MSSQLSERVER,1433
    S Stanciu Vlad

    Hey, Glad to see you've progressed! I have a couple of commentaries: 1) 127.0.0.1 is the ip of the loopback interface, so if you use the loopback then you use no network (so this was a network problem, probably missing network connection?) 2) the data adapter da is not retriving any rows because it has no select command. You should use this line of code SqlCeDataAdapter da = new SqlCeDataAdapter(comm); 3) there is no use form the data reader dr 4) sql ce data adapter does not work with sql command or sql connection... 5) it is usefull to bind data to the combo box in order to maintain relation with your database entity. I recommend this snippet of code:

    string sConnection = "Data Source=127.0.0.1,1433;Persist Security Info=True;Initial Catalog=GMAO;User ID=sa;Password=sa";
    string sSQL = "SELECT ID, com FROM energie";

    SqlConnection conn = new SqlConnection(sConnection);
    SqlCommand comm = new SqlCommand(sSQL, conn);
    SqlDataAdapter da = new SqlDataAdapter(comm);

    try
    {
    DataSet ds = new DataSet();

    comm.Connection.Open();
    
    da.Fill(ds);
    
    comboBox1.DataSource = da.Table\[0\];
    comboBox1.DisplayMember = "com";
    comboBox1.ValueMember = "ID";
    

    }
    catch (SqlException ex)
    {
    MessageBox.Show(ex.Message);
    }
    finally
    {
    comm.Connection.Close();
    }

    I have no smart signature yet...

    C# csharp database sql-server visual-studio linq

  • how to insert a new line in a table of a .sdf file smart device application
    S Stanciu Vlad

    Most probably the table opened from visual studio is just a local copy of the database file. Your operation is made on the smart device simulator, on that database. You can download the file from the smart device and check the row is inserted, or you can execute a select command on the device to check the row count.

    I have no smart signature yet...

    C# help com tutorial
  • Login

  • Don't have an account? Register

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