Mitja Bonca 557 Nearly a Posting Maven

Memorath, how would you do that what you said? Would like to see that too.

Mitja Bonca 557 Nearly a Posting Maven

Put the values from the row into Body tag of MailMessage class.
What you can do it to loop through the rows of dgv, and concat data from each row and send mail.

To do a loop you can do:

For Each row As DataGridViewRow In datagridview1.Rows
    'mail to send code and:         
    mail.Body = String.Format("Location: {0}, Date: {1}, Price: {2}", row.Cells(0).ToString(), row.Cells(1).ToString(), row.Cells(1).ToString())
    'i pass data from 1st, 2nd and 3rd column
    'and rest of the code..
Next
Mitja Bonca 557 Nearly a Posting Maven

Not its not the same way. Its more awkward then before - at least for me. But I need some time, and I wont even notice the difference.

Mitja Bonca 557 Nearly a Posting Maven

Damn, how to add code snipet?
I got it, even if its a bit lame.

Mitja Bonca 557 Nearly a Posting Maven

I would do it differenty. I would run Login form before starting the main form (with application.Run).
Take a look at here:

 static class Program
 {
   [STAThread]
   static void Main()
   {   
       using (Login login = new Login())
       {
            login.StartPosition = FormStartPosition.CenterScreen;
            if (login.ShowDialog() == DialogResult.OK)
            {      
                  Application.Run(new Form1(login.strUserName)); //passing the userName to the constructor of form1 (from Login form - global variable)!
            }
       }
    }
}

//form1:
public partial class Form1 : Form
{  
     string userName; 
     public Form1(string _strUser)
     {   
           InitializeComponent();
           userName = _strUser; //a local variable of a form1 class has hold user`s name (userName - which u can call it from within the form1 class!
     }
}

public partial class Login : Form
{
       public string UserName { get; private set; } 
       public Login()
       {
              InitializeComponent();
       }

       private void btn_Login_Click(object sender, EventArgs e)
       {
             string userName = textBox1.Text.Trim();
             string pswd = textBox2.Text.Trim();
             bool bLoginOk = CheckUser(userName, pswd);
             if (bLoginOK)
             {
                  this.DialogResult = DialogResult.OK;
                  this.UserName = userName; //setting global variable (a property) so it can get the name out of it later (from program.cs)
                  //code will close login form, and go back to program.cs ...
             }
             else
            {
                 //you can show here a messageBox that userName and password do not match if you like!
                 //AND the login form still stays open!!
            }
      }


      private bool CheckUser(string name, string pswd)
      {
            bool bChecking = false;

            //do the login checking, if username and password match, return true, else false

            //if username and password match:
            bChecking = true;

            return bChecking;
      }     
}
Mitja Bonca 557 Nearly a Posting Maven

Exactly what darkagn said. Variable "data" is null. Your dataTable do not get fill up. Check like he expalined.
The method "DataTable data = App.getGenericData(sqlString);" does not return anything. Check that method.

Mitja Bonca 557 Nearly a Posting Maven

You are using what? Access or sql? These are 2 difference concepts.
You can use varchar (string).

Mitja Bonca 557 Nearly a Posting Maven

Why you dont want to show all the records from the text file in datagridview at ones?
Like:

string[] rows = File.ReadAllLines(@"C:\1\test35.txt");
            DataTable table = new DataTable("customers");
            table.Columns.AddRange(new DataColumn[] 
            { 
                new DataColumn("First name", typeof(string)), 
                new DataColumn("Middle name", typeof(string)), 
                new DataColumn("Last name", typeof(string)), 
                new DataColumn("Born", typeof(DateTime)), 
                new DataColumn("Gender", typeof(string)) 
            });
            DataRow dr;
            for (int i = 0; i < rows.Length; i++)
            {
                string[] columns = rows[i].Split(',');
                dr = table.NewRow();
                if (columns.Length == 5) //with middle name
                {
                    dr["First name"] = columns[0];
                    dr["Middle name"] = columns[1];
                    dr["Last name"] = columns[2];
                    dr["Born"] = columns[3];
                    dr["Gender"] = columns[4];
                }
                else if (columns.Length == 4) //no middle name (if it might occur)!
                {
                    dr["First name"] = columns[0];
                    dr["Last name"] = columns[1];
                    dr["Born"] = columns[2];
                    dr["Gender"] = columns[3];
                }
                table.Rows.Add(dr);
            }
            //bind table to datagridview:
            dataGridView1.DataSource = table.DefaultView;
ddanbe commented: Nice. +15
Mitja Bonca 557 Nearly a Posting Maven

Where exactly do you wanna show the data? In textBoxes or in some data collection control (like datagridview)?
Depends on data binding.

Mitja Bonca 557 Nearly a Posting Maven

Try do use StreamReader class to read the file line by line, and count repetitions of char:

Dim counter As Integer = 0
Using sr As New StreamReader("filePath")
	Dim line As String
	Dim data As String() = Nothing
	While (InlineAssignHelper(line, sr.ReadLine())) IsNot Nothing
		If line.Contains("*"C) Then
			data = line.Split(New Char() {"*"C}, StringSplitOptions.None)
			counter += data.Length - 1
		End If
	End While
End Using
MessageBox.Show("char * was counted: " & counter & " times")
Mitja Bonca 557 Nearly a Posting Maven

I see, sorry.
On new form put textboxes. On form where DGV is, create an array of data (of selected row) and paste to new form and show data from array in textBoxes.
Exmple:

Dim data() As String = New String((dataGridView1.Columns.Count) - 1) {}
For Each row As DataGridViewRow In dataGridView1.SelectedRows
    Dim i As Integer = 0
    Do While (i < row.Cells.Count)
        data(i) = row.Cells(i).Value.ToString
        i = (i + 1)
    Loop
    Exit For
    'only 1st selected row will be used (you can remove it)
Next
Dim f2 As Form2 = New Form2(data)
'on form2:
Class Form2
    
    Public Sub New(ByVal data() As String)
        MyBase.New
        textBox1.Text = data(0)
        'and so on...
    End Sub
End Class
Mitja Bonca 557 Nearly a Posting Maven

You went to right direction saleem, but you should only use DataGridViewRow class.
Why? You cannot select more then 1 row, since you only have 1 textBox for each column (so array of rows drops off here).
You can do:

Dim row As DataGridViewRow = dataGridView1.SelectedRows(0)
txtHotelId.Text = row.Cells(0).Value.ToString()
txtHotelName.Text = row.Cells(1).Value.ToString()
txtContactPerson.Text = row.Cells(2).Value.ToString()
txtLocation.Text = row.Cells(3).Value.ToString()
txtPhone.Text = row.Cells(4).Value.ToString()
TxtFax.Text = row.Cells(5).Value.ToString()
txtEmail.Text = row.Cells(6).Value.ToString()
txtAddress.Text = row.Cells(7).Value.ToString()
Mitja Bonca 557 Nearly a Posting Maven

Because the value of MyInteger changed, and would, therefore change the return value of MyMethod(), does it actually change it, or is MyValue still false after MyInteger gets a new value?

I understand completely.
When your "MyValue" variable get new value of true, false is no longer available.
The MyValue get changed instantly when you assign to it in another method - if this is what you would like to know (ones again, its get overwritten in the moment you assign new value to "return true", or "return false".

Mitja Bonca 557 Nearly a Posting Maven

When you call Dispose() method on some object, it means it is completey shuted down (you can understand it to be more then Closed - while closed object you can still access to it with its reference).
So Disposed objects are like then is no reference to them (not exisitng anyhow, and anylonger).

Concerning your example, your reference of a class must be an the class level, not on event level (now you create a new reference of the new form every time you click on the button).

Look at darkagn example, but you can still do it like:
Project1.Form1 prjform = new Project1.Form1(); //on class level you instanitate reference of a form (it will be done jsut before form load

private void mouseClkbtn_Click(object sender, EventArgs e)
        {
              if (mouseClkbtn.Text == "Latch Enable")
                {                   
                    prjform.Show();
                    mouseClkbtn.Text = "Latch Disable";
                }
                else if (mouseClkbtn.Text == "Latch Disable")
                {
                    prjform.Hide();
                    prjform.Dispose();
                    mouseClkbtn.Text = "Latch Enable";
                }            
        }
Mitja Bonca 557 Nearly a Posting Maven

No, but its MSSQL -this is Microft database, but its Express editon, that means its capacity is limited to 2GB (in VS 2010 the limit it 4GB).

Mitja Bonca 557 Nearly a Posting Maven

any why would you like to get previous value? There is no sence.
Anyway, if you wanna hold multiple values in one variable, I would suggest you to use Dictionary (key will be index (like counter from 0,1,2, and up), while value will be an actual state of variable (in your case true and false will be chaging).
Example:

Dictionary<int, bool> dic = new Dictionary<int, bool>();
int counter = 0;
//inside your method:
private void DoWork()
{
     dic = MyMethod();
}

private Dictionary<int, bool> MyMethod()
{
    bool bFlag = true, or false; //swapping values...
    dic.Add(counter, bFlag);
    counter++; //rise it by 1 for next time round
    return dic;
}

Even MyMethod could return void, since dic variable is accessible in the whole class. Anyway, I only wanted to show an exmaple.
One more last thing: you can simply then loop through the dictionary and check the boolean states:

foreach(KeyValuePair<int, bool> kvp in dic)
{
    //in each iteration:
    int key = kvp.Key;
    bool bValue = kvp.Value;
}

Hope it helps.

Mitja Bonca 557 Nearly a Posting Maven

No, variable ONLY holds one value. So the last passed to it. If you "overwrite" false with true, there is no way to get false back. Only true is available.

Mitja Bonca 557 Nearly a Posting Maven

Your main problem was you only specify 3 value to be updates, then you add 4 parameters!

Next:
What exact data type are the columns in the data table?
My assumption:
- pic id - integer
- pic - image (you must pass a byte array to db)
- caption - varchar (50 length)

This is how you must have, and then you do:

byte[] ins = GetBinaryFile(txtDIR.Text);
int x = 1;
string comm = "INSERT INTO pictable (pic id, picDirectory, pic, caption) values(@picID, @picDirectory, @pic, @caption)";

OleDbCommand cm = new OleDbCommand(comm, cn);
cm.Parameters.Add("@picID", OleDbType.Int).Value = x; //no object casting!
cm.Parameters.Add("@picDirectory", OleDbType.VarChar, 50).Value = txtDIR.Text;
cm.Parameters.Add("@pic", OleDbType.Image).Value = ins;
cm.Parameters.Add("@caption", OleDbType.VarChar, 50).Value = txtCaption.Text;
cm.ExecuteNonQuery();

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

Check the list here.

Mitja Bonca 557 Nearly a Posting Maven
1. dateTimePicker1.MinDate = DateTime.Today
2. dateTimePicker1.MinDate = new DateTime(2012, 2, 3) 'your departure date
3. 'dont know what it means

Anwyay, you see how you can set youur datetimepicker (use MinDate or MaxDate, to determine lower and upper date).

Mitja Bonca 557 Nearly a Posting Maven

or do a loop through all the textboxes and clear them (or what ever you want to do with them):

For Each t As TextBox In Me.Controls.OfType(Of TextBox)()
	t.Text = String.Empty
Next
Reverend Jim commented: "OfType(Of TextBox)" cool. I didn't know that one. +9
M.Waqas Aslam commented: i also dont know this quick method .:P thanks +5
Mitja Bonca 557 Nearly a Posting Maven

What do you have to validate in dateTimepicker control? There is always a datetime selected (and shown). There cannot occur any error.
Explain what do you want to validate.

If you will use Value property of selected date, you will always get certain and real datetime value.

Mitja Bonca 557 Nearly a Posting Maven

Then you can mark this thread as being answered.
thx
bye, bye

Mitja Bonca 557 Nearly a Posting Maven

Show me your code.

Mitja Bonca 557 Nearly a Posting Maven

Impossible.
If you want to disable a control, you have to use "Enabled" property of a control. And it must be set to false.
Or you can even use "ReadOnly" property, which has to be set to true (to be disabled).

Mitja Bonca 557 Nearly a Posting Maven

at the buttom of the page there is a button " mark as asnwered" or something.

Mitja Bonca 557 Nearly a Posting Maven

Check here more about Process.Start, method (when overloads stirng parameter).

Mitja Bonca 557 Nearly a Posting Maven

Yep, I would only recommend you to use parametriezed query, so you specify the parameter in additional like of code:

cmd.CommandText = "Delete From bookings where Bk_id = @param1"
cmd.Parameters.Add("@param1", SqlDbType.Int).Value = Integer.Parse(dataGridView1(0, dataGridView1.CurrentRow.Index).Value.ToString())
Mitja Bonca 557 Nearly a Posting Maven

DO NOT use the form load event for populating control (on form2), becuase it will rise only 1 time (only when form opened).
Better create a new method on form2, and call it each time you want to pass some data from form1 to form2. This way you can execute it when ever you want.

Mitja Bonca 557 Nearly a Posting Maven

Dear All,

I had developed a desktop application that searches word files contents in a folder for a specific word(s) .It's working fine, but it's slow.

I want to apply indexing(or any other technique) to speed up the performance of my application ... I want to know how to apply indexing step by step as I didn't apply it before.

Would you mind showing us your code?
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

TextChnaged event will not fire while pressing Enter key (carriage return).
To get this key pressed, you have to consider of using any of KeyPress events, like:
KeyDown:

c

or here is another option:

private void ByteData_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
    {
         // Then Enter key was pressed
    }
}

If you still want to run the next code from TextChanged event, you can do something like:

private bool bFlag;
public void ByteData_TextChanged(object sender, EventArgs e)
{
     DataString.Append(ByteData.Text);
     if(bFlag)
     {
          //do your code in here after Enter key is pressed
     }
}

private void ByteData_KeyDown(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        bFlag = true;       
    }
}

... but this is a lame way to do coding.
I would prefer to call the method (with additional code) directly from KeyDown event, when Enter key is pressed.

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

You are welcome.
So, have you managed to make your code working?

Mitja Bonca 557 Nearly a Posting Maven

Use DataView class and RowFilter property of it, to specify the filter.
But before that fill the dataTable and use databinding (datatable has to be a binding source of datagridview control).

You can find an example here.
bye

Mitja Bonca 557 Nearly a Posting Maven

I would open file from double clicking on the item in comboBox, rather then with a button click (which is an additional - unnecessary task to do - if we are picky).

So to open more files, you can use Shitch statement, and specify what ever you need in each of the cases.

Example:

private void comboBox1_DoubleClick()
{    
    switch(comboBox1.SelectedItem.ToString())
    {
         proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
         proc.StartInfo.Verb = "print";
         proc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe";
         
         case "Bilans stanja":
         {
              proc.StartInfo.Arguments = @"C:\Users\RS\Desktop\PDF\Obrasci finansijskih izveštaja\Bilans stanja.pdf";       
              break;
         }
         case "Bilans uspeha":
         {
             proc.StartInfo.Arguments = @"C:\Users\RS\Desktop\PDF\Obrasci finansijskih izveštaja\Bilans uspeha.pdf";
             break;
         }
         //do the same for the rest
      
         proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
    }
}

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

I cannot see the image, and since you didnt write anything about the issue, we cannot help you out yet. So please...
But regarding your thread`s title, I can see you are trying to access to some control`s property, which you cannot directly.
Why not?
Because control is created on UI (main) thread, and since you run some code on a newly created thread, you cannot access control`s properties from it.
You already mentioned delegates, thats exactly what you need. So if you know how to use them, try it out.
In this is in no help, please upload the image ones again, or describe the issue a but better.
thx
bye

Mitja Bonca 557 Nearly a Posting Maven

How to convert automatically system genrated string to int in c# code.

Im not sure what do you mean?
If you have a number, you can do in many ways:

string yourString ="...."; //some value, you said its a number
int myInt = 0;
if(int.TryParse(yourString, out myInt)
{
    //here you can use your string converted into real number (type of integer)
}
else
    Console.WriteLine("This is not a number");

//or you can use:
int.Parse("your value");
or:
Convert.ToInt32("your value");

Hope it help,s if not provide us some better description of this issue of yours.
bye

Mitja Bonca 557 Nearly a Posting Maven

1. Do not create controls public - keep them private.
2. Use form1`s reference on form2, so you can access memebers of form1 from form2.

Then simply use this reference on form2 to get the value (you want to) from form1.

Mitja Bonca 557 Nearly a Posting Maven

I'm sorry I'm still a beginner at this. What are "DAL" and "BL?"

never mind, do it this way:

//assembly 1:
namespace Mar14_Part1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }

    public class MyClass
    {
        public string MyMethod()
        {
            return " some text from other assembly";
        }
    }
}

//assembly 2:
//add reference of assemby1 like I told you on top
then do:
using Mar14_Part1;

namespace Mar14_Part2
{
    class Program
    {
        static void Main(string[] args)
        {
            MyClass mc = new MyClass();
            string str = mc.MyMethod();
            Console.WriteLine(str);
            Console.ReadLine();
        }
    }
}

Mine example works!

Mitja Bonca 557 Nearly a Posting Maven

You can only reference in one way otherwise you get the error like you said. Just do this: delete the reference from your DAL to your BL and make a new one from your BL to your DAL!

Mitja Bonca 557 Nearly a Posting Maven

This is what you have to do exactly:

1.
The first step is to make P2 reference P1 by doing the following:

Right Click on the project and select "Add Reference";
Go to the Projects Tab (or Browse Tab);
Look for P1, Select it and hit OK;

2.
Next you'll need to make sure that the classes in P1 are accessible to P2. The easiest way is to make them public:

public class MyType { ... }

3.
Now you should be able to use them in P2 via their fully qualified name.
Assuming the namespace of P1 is Project1 then the following would work:

Project1.MyType obj = new Project1.MyType();

4.
The preferred way though is to add a using for Project1 so you can use the types without qualification:

using Project1;
...

public void Example()
{
MyType obj = new MyType();
}

Mitja Bonca 557 Nearly a Posting Maven

vshost file (in program/bin/debug)

Mitja Bonca 557 Nearly a Posting Maven

or this:

string dirPatgh = @"C:\MyFolder\";
DirectoryInfo di = new DirectoryInfo(dirPath);
// Get a reference to each file in that directory.
FileInfo[] files = di.GetFiles();
foreach(FileInfo file in files)
{
   listbox1.Items.Add(file.Name);
}
Mitja Bonca 557 Nearly a Posting Maven

You have to add a reference of the project you want to access to (right click on References in solution explorer, then select Add Reference, then select Browse tab and look for appropriate file in the project you want to access).
Then Add this reference on the top on the class you want to access from (using YourProjectname).
Then you should see the pulbic members of the class you access.

Mitja Bonca 557 Nearly a Posting Maven

Would you mind showing us your code, the one you think it might cause problems?

Here is some good article about this problem, read it, it might give you an idea.

Mitja Bonca 557 Nearly a Posting Maven

When you instanitate new variables, specify their beggining values, like:

//instead of:
double rate, year, presentValue, futureValue;
//do:
double rate = 0, year = 0, presentValue = 0, futureValue = 0;
Mitja Bonca 557 Nearly a Posting Maven

Thanks alot Mitja! I hope that this will work :) You are from slovenia like me? :)

yes :), Lj, but only live there.
So have you solved the issue?

Mitja Bonca 557 Nearly a Posting Maven

Maybe something like this:

static int Find(int el, int[] a)
        {
            int index = -1;
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == el)
                {
                    return a[i];
                }
            }
            return index;
        }
Mitja Bonca 557 Nearly a Posting Maven

come on stop making duplicate threads. One will do it.

Mitja Bonca 557 Nearly a Posting Maven

This is all the code you need:

//on form1:
        int counter;
        Form2 f2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (counter < 5)
            {
                f2 = new Form2();
                counter++;
                f2.Show();
            }
            else
                MessageBox.Show("Form2 cannot be opened any longer.");
        }
Mitja Bonca 557 Nearly a Posting Maven

What do you do with the "dTableShowPlaylist"?
there is no code that would show of any use.