Mitja Bonca 557 Nearly a Posting Maven

That you dont have any loop around the code which shows the progressBar?
Or maybe you call the method multiple times?
Please double check it.

Mitja Bonca 557 Nearly a Posting Maven

I know it can be creates like:

TextBox[] tbsArray = new TextBox[2];
tbsArray[0] = textBox1;
tbsArray[1] = textBox2;

//or:
TextBox[] tbsArray = new TextBox[] { textBox1, textBox2 };

//or in a loop:
foreach(TextBox tb in new TextBox[] { textBox1, textBox2 })
{
     //...
}

If there is any other way you would like to have it, let us know.
bye

Mitja Bonca 557 Nearly a Posting Maven

As Jorge mentions, it seems like you accidentally zoomed out in Chrome. From the Tools menu, click Zoom to 100%. You can also hold down the Ctrl key and scroll the mouse up.

This was partly true, but not the zoom that was doing problems, in new chrome there is an icon beside zoom, just clicked on it, and now its all fine :)
thx god!
And thx for your decent explanation. I hope daniweb returns to its best days :)
best regards

Mitja Bonca 557 Nearly a Posting Maven

No, zoom has nothing to do with it! Its only this webiste that it has been reduced its size. Its like 1/4 of a whole screen resolution (in 1680x1050)

Mitja Bonca 557 Nearly a Posting Maven

Hi, since this forum has been modified majorly (this happened approx. 6 months ago) nothing works at it should. There is a lot less people asking question (and answering on them), it seems like you have driven them away with these (not-good changes -personally it was whole much better before that huge webiste update), nor the forum it self does not work like it should.
And a few days ago (including today) the forum size has been shrinked, redused to some small size (like 600x400 pixels). This is refering to Chrome web browser, in Opera seem to be all ok.
What is going on here?

I just want to remind you, if this is keep on happening, people will go from here (leaving), to other forums. Just to keep you awake, I dont think nothing bad with this few statements of mine! I hope I will wake you up moderators and people who are responsable for this (used to be) great forum!

Mitja

Mitja Bonca 557 Nearly a Posting Maven

YOu have to be aware of one thing: when you close the form (main form you named it), which has been started from Program class with:

 Application.Run(new Form1());

The application will close.
To avoid this, you have to take care of closing all other form before this one.

Mitja Bonca 557 Nearly a Posting Maven

Why dont you use a normal TextBox control instead of MaskeTextBox?

In IP case, it would be a better option.

Anyway, if you would like to use MaskeTextBox, and if you wanna remove spaces use Replace method of string class:

            string input = "23 .1 .001.200";
            if (input.Contains(" "))
                input = input.Replace(" ", "");
Mitja Bonca 557 Nearly a Posting Maven

DO NOT make controls public. This is the worse case possible. This is never a good way of (unsafe) coding.
You have other better options:
- by creating a method on form1 which can be access from form2 to access control on form2
- by using events

but in any case, you will need a reference of form2 (but I know you have it).

Mitja Bonca 557 Nearly a Posting Maven

You cannot access control which were creates on one (usually on UI) thread, from another thread. You will need to Invoke control.
For more info read here: http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx

FOr example to clear selection do:

listBox1..Invoke(() => listBox1.ClearSelection());
Mitja Bonca 557 Nearly a Posting Maven

This code:

if(RadioButton1.Checked) 
{
    Form2 f2 = new Form2();
    f2.Show();
} 
else if (RadioButton2.Checked)
{
    // do something else
}
Mitja Bonca 557 Nearly a Posting Maven

Use int.Parse() method:

if (int.Parse(row.Cells[3].Value.ToString()) >= -1)
{
   //do work...
}
Mitja Bonca 557 Nearly a Posting Maven

If you bind some data from the dataSource to DGV control, Remove the row from the datasource, not from the DGV. This will reflest in removing row from DGV as well.

Mitja Bonca 557 Nearly a Posting Maven

Do the loop through the rows of dgv and check if row is selected:

   using(SqlConnection conn = new SqlConnection("connString"))
   {     
       foreach (DataGridViewRow dr in dataGridView2.Rows)
       {    
           DataGridViewCheckBoxCell check = row.Cells[0] as DataGridViewCheckBoxCell;
           if(check != null && (bool)check.Value) //1st parameter must not be null, 2nd parameter must me true!
           {
               string query = @"UPDATE TableName SET FieldName2 = @param1 WHERE FieldName1 = @param2"; //query
               using(SqlCommand cmd = new SqlCommand(query, conn))
               {
                   cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50).Value = row.Cells["ColumnName2"].Value.ToString(); //set appropriate column name or its index
                   cmd.Parameters.Add("@param2", SqlDbType.Int).Value = int.Parse(row.Cells["ColumnName1"].Value.ToString()); //same here!! - this is some id (unique) column
                   try
                   {
                       if(conn.State != ConnectionState.Open)
                           conn.Open();
                       cmd.ExecuteNonQuery();
                   }
                   catch(Exception ex)
                   {
                       MessageBox.Show(ex.Message);
                       break; //go out of the loop when 1st error occurs! - you can remove it
                   }
               }
           }
       }
   }  
Mitja Bonca 557 Nearly a Posting Maven

Have you set column names? And I would suggest you to set View to Details, not to List or any other type.

Mitja Bonca 557 Nearly a Posting Maven

How do you intend to pass the data from DGV to textBox? On a row (cell) click?
Some other way?
If so, do it like:

textBox1.Text = dgv[ColumnIndex, RowIndex].Value.ToString();

if you want to add data to textBox (multiline) use += insted of = only and add "\r\n" before code:

textBox1.Text += dgv[ColumnIndex, RowIndex].Value.ToString() + "\r\n"; //for adding new line for next insert
daniel955 commented: nice +1
Mitja Bonca 557 Nearly a Posting Maven

Hi,
can you show us your code? No need to paste it all here, but only the basic one, so we can see whats all about.
thx

Mitja Bonca 557 Nearly a Posting Maven

Hi,
I would recommend you to fill DataTable from DGV, but there is still not in-built way to do so.
check this link: http://stackoverflow.com/questions/4720463/how-to-export-from-datatable-to-pdf-in-wpf

Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to use events.

Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

Retreive the id from the selected tiem, by using DataRowView class:

DataRowView view = comboBox1.SelectedItem as DataRowView;
int id = int.Parse(view["IdColumnName"].ToString());
//us id variable as a value to insert to db.
Mitja Bonca 557 Nearly a Posting Maven

Hi,
how do you add to table1 from dgv2? My guess is that you add 2 more columns, instead of adding data to 1st and 2nd columns only (so bellow the previous data).

Mitja Bonca 557 Nearly a Posting Maven

Use StreamReader to read line by line (rows), and a comma delimiter to split each line (columns).
Then you can for each row do insert or update into database, since you have all the values of a row.
Hope it helps.

Mitja Bonca 557 Nearly a Posting Maven

On every step of the way through the method the code must return some value, if it cannot continue from there.
So every if, else if and else must return it.

Mitja Bonca 557 Nearly a Posting Maven

Hi,
No code, no question.
Sorry.

Mitja Bonca 557 Nearly a Posting Maven

DO:

//on main form:
void OpenClient()
{
    Client c = new Client(this);
    c.DoWork();
}

public void AddText(string text)
{
    this.richTextBox1.AppendText(text+Environment.NewLine);
}

//on client class:
class Client
{
    MainForm mf;
    public Client(MainForm _mf)
    {
        this.mf = _mf;
    }

    public DoWork()
    {
        string text = "";
        //do some work ... and add value to text field;
        //and pass to rtb on main form:
        mf.AddText(text);
    }
}
Mitja Bonca 557 Nearly a Posting Maven

You only need the correct connection string to access to database.
And if SSMS (with database) is located on different pc, then you have to open a 1433 port (potr that is used to access to sql server by defalut) in the firewall.

Mitja Bonca 557 Nearly a Posting Maven

You cannot remove items while inisde loops, nor for or foreach loop.
You will have to create a new list, where you will put numbers to delete, or indexes of them, and then add the duplicates inside out it. After this is done, you will have to do another loop through this new list and remove numbers from original list.

Mitja Bonca 557 Nearly a Posting Maven

Multiply?
Do you mean, when you select an item on comboBox1, you ADD this item to comboBox2?
Is fo, use Add() method.

comboBox2.Items.Add(comobBox1.SelectedItem)
Mitja Bonca 557 Nearly a Posting Maven

When exactly do you wanna clear it? When you click on it, or double click on it?
PS: Create specific event where you wanna do that exactly.

Mitja Bonca 557 Nearly a Posting Maven

Or I would use

sb.AppendLine(line);

This will put lines into each line (same as in file).

Mitja Bonca 557 Nearly a Posting Maven

If the file is "in-use", you cannot delete it.

Mitja Bonca 557 Nearly a Posting Maven

Check out this way by using DialogResult (and passing data between forms or classes):

'PROGRAM class    
Class Program

    ''' <summary>
    ''' The main entry point for the application.
    ''' </summary>
    <STAThread()>  _
    Private Shared Sub Main()
        Application.EnableVisualStyles
        Application.SetCompatibleTextRenderingDefault(false)
        Dim loginData As String = ""
        Dim l As Login = New Login
        If (l.ShowDialog = DialogResult.OK) Then
            'code returns form login (if you want you can get some data from there and pass it further:
            loginData = l.MYPROPERTY
        End If
        Application.Run(New Form1(loginData))
    End Sub
End Class
' LOGIN:
Public Class Login
    Inherits Form

    Public Property MYPROPERTY As String
    End Property

    Public Sub New()
        MyBase.New
        InitializeComponent
    End Sub

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        'all ok..
        'and close login form (and pass data if you want)
        MYPROPERTY = "hi from login"
        Me.DialogResult = DialogResult.OK
    End Sub
End Class
'MAIN FORM:
Public Class Form1
    Inherits Form

    Public Sub New(ByVal loginData As String)
        MyBase.New
        InitializeComponent
        MessageBox.Show(loginData)
        'Do with the data what ever you want to...
    End Sub
End Class
Mitja Bonca 557 Nearly a Posting Maven

What exactly do you have in mind?
Maybe you want to create a derived class from a base class, and use a new keyword on a return type.
Check here: http://www.akadia.com/services/dotnet_polymorphism.html

Mitja Bonca 557 Nearly a Posting Maven

For the 1st part (checking username and password match) you can do the same as for login check (you can even use that code).
For last one, to check if two passowrds are equal (in textboxes) simply do:

if(textBoxPswd1.Text == textBoxPswd2.Text)
{
   //passwords both equal, so continue
}
else
{
    //passwords do not match
}

For the insert new passord you have to use an sql UPDATE query like:

SqlConnection conn = new SqlConnection("connString");
string query = @"UPDATE Users SET Password = @pass WHERE Username = @user";
SqlCommand cmd = new SqlCommnand(query, conn);
cmd.Parameters.Add("@pass", SqlDbType.VarChar, 50).Value = textBoxPswd1.Text;
cmd.Parameters.Add("@user", SqlDbType.VarChar, 50).Value = textBoxUsername.Text;
conn.Open();
cmd.ExecuteNonQuery();
cmd.Close();
conn.Close();

NOTE: change table name and fields appropreately. I only used example names.
Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

Mate,
tell us what EXACTLY IS that you want from the filering. Select query is doing EXACTLY what you tell it. And it does 100% fine.
The problem is only in your string.

To blindly guess what do you need is:

string strSelect = string.Format("DeviceId = '{0}' AND Feederstatus <>'{1}'", int.Parse(strDevId), strFeedStat);

<> means IS NOT equal.

Is there something else you want to use Feederstatus field?

Mitja Bonca 557 Nearly a Posting Maven

You can do in a loop:

int x = 20, y = 20; //initial location x and y
for(int i = 0; i < 2; i++)
{
    Label l = new Label();
    l.Position = new Point(x, y);
    l.Text = i == 0 ?" Text for label 1" : "Text for label 2";
    this.Controls.Add(l);
    //set new location for next:
    x+= 50; //2nd will be 50pixels to the right
}
Mitja Bonca 557 Nearly a Posting Maven

You can do a loop through rows:

For Each row As DataGridViewRow In dgv.Rows
    row(0).Value = Integer.Parse(row(1).Value.ToString()) + Integer.Parse(row(2).Value.ToString())
Next

Explanaiton: This will show the sum of column1 and colum2 in column0 OF ALL ROWS!

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

Dont your have some missmatch there?
You want to have a sum from
row 1 and cell 1 +
row 1 an cell 2 =
row 0 and cell 1

Isnt this a bit strange?

Are you possitive this is it?

I would use 1st column as JAN total, 2nd column as FEB total ,.... and the last Column would be the sum from all previous columns.

Tell me your thoughts.

Mitja Bonca 557 Nearly a Posting Maven

and if my ids are int ?

Then do:

DataRowView view = comboBox1.SelectedItem as DataRowView;
da.InsertCommand.Parameters.Add("@Town", SqlDbType.Int).Value = int.Parse(view["ID_Town"].ToString());

thats it.

Mitja Bonca 557 Nearly a Posting Maven
  1. String is a type, that represents a string of Unicode characters. string is an alias for System.String in the .NET Framework.
  2. String() is an array (more strings "together" can make an array of strings).
  3. Spit my white spaces (" "c).
  4. Reverse is a method of String class, that can turn around (in exactly reversed order) - and does not change anything else (you said you want to have written words in reverse order -so this does that - BUT its does not reverse charcters of each string).
  5. Join creates a string from an array. And he defined ("Join(" ", Array) - this means Join what is in array, and make white space between each string)

This is it!

Hop it helps a bit.

btw, here is my version of reversing string:

Dim str As String = "reverse this string"
Dim reverseStr = str.Split(" "C)
.[Select](Function(a, b) New With { _
    Key .WORD = a, _
    Key .INDEX = b _
})
.OrderByDescending(Function(o) o.INDEX)
.[Select](Function(s) s.WORD).ToArray()
.Aggregate(Function(a, b) Convert.ToString(a) & " " & Convert.ToString(b))

Dont be scared, this is just a Linq ("simplifies" things sometimes :) ).

bye

Mitja Bonca 557 Nearly a Posting Maven

Hi,
The main question is, are data in DGV bound to some collection (datatable for instance)?

Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

or:

Also, you can use this if you don't want to use the System.Web assembly:

var encoded = System.Security.SecurityElement.Escape(unencoded)

Per this article, the difference between System.Security.SecurityElement.Escape() and System.Web.HttpUtility.HtmlEncode() is that the former also encodes apostrophe (') characters.

Mitja Bonca 557 Nearly a Posting Maven
Imports System.Web
Dim encoded As var = HttpUtility.HtmlEncode(unencoded)
Mitja Bonca 557 Nearly a Posting Maven

Anytime.
But remember, marking members as static, this means they stay in the memory as long as an application is alive.
Personally I would avoid using static members, and rather choose 2nd option I gave you.
Just for you notice.

ps: if issue has been resalved, please mark the thread as answered.
thx
bye

Mitja Bonca 557 Nearly a Posting Maven

When populating DGV, do it with databinding from DataTable. So when changes to DGV will be made, all will reflect in datatable as well. Then do an Update sql query to update database.
Check here how it can be done.

Mitja Bonca 557 Nearly a Posting Maven

Create a DataTable, do the SELECT statement of that number (column name) from database, and do the filtering, if the number already exists in dataTable. I would suggest using Linq - its simple and fast.

It should be like:

            int textBoxNumber = int.Parse(textBox1.Text);
            DataTable table = new DataTable("Numbers");
            using (SqlConnection conn = new SqlConnection("connString"))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT ShopID FROM ShopType", conn))
                    da.Fill(table);
            }
            if (table.Rows.Count > 0)
            {
                IEnumerable<DataRow> query = table.AsEnumerable().Where(w => (int)w["ShopID"].ToString() == textBoxNumber);
                if (query.Count() == 0)
                {
                    //no number yet
                }
                else
                {
                    //number already exists!
                }
            }
            else
            {
                //show message there is no number in db yet
            }

IMPORTANT: my code assumes your ID is a number (integer). If your field in dataBase is an integer there will be no problem, but if its a varchar (string), then change this code to:

.Where(w => (string)w["ShopID"] == textBox1.Text); //must be a string

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

Close this thread (if this is the thread you created).
And create a new one.

Mitja Bonca 557 Nearly a Posting Maven

One option would be to set accessor modifier of the dataSet to public static. Then you can access to dataSet simply ba Form name, like:

class MyClass
{
    public static DataSet myDataSet;
}

class MyOtherClass
{
    void MyMethod()
    {
        DataSet ds2 = MyClass.myDataSet;
    }
}

Next option would be (not to use a static access modifer), to use a class`s reference and access to dataSet by it:

    class MyClass
    {
        public DataSet myDataSet; //must be public to access from other classes
        void OpenOtherClass()
        {
            MyOtherClass c2 = new MyOtherClass(this); //pass a reference of this class

        }
    }

    class MyOtherClass
    {
        MyClass mc;
        public MyOtherClass(MyClass _mc)
        {
            this.mc = _mc;
        }
        void MyMethod()
        {
            DataSet ds2 = mc.myDataSet;
        }
    }

Or even 3rd option would be to use events. And trugger it to access to it. But this is not what you would like to learn yet. Maybe later.

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

Is your gridView databound?"(
Do you have a new field in datatable like "Status", like you have it in grid view?
When you will press a Delete button in gridview, the row will get deleted, but even a field in database must be set to false (or some other value that you (code) will know that row has been deleted, and next time when populating grid view will NOT be shown again).
Thats why you need a new sql SELECT statement like:

"SELECT * FROM MyTable WHERE status = 'false'"

--
To delete a row, its not a good practice to delete (remove) it straight away, but you have to get a row index (or gridviewrow object) , and delete it afterwards when you are done looping through the rows of grid view. To acomplish that you need (for example) a new list<T>, into which you will or row index or row object.