Mitja Bonca 557 Nearly a Posting Maven

You can set tje order of the columns like:

dataGridView1.Columns["Name"].DisplayIndex = 0;
    dataGridView1.Columns["RegNo"].DisplayIndex = 1;
    dataGridView1.Columns["Adress"].DisplayIndex = 2;
kvprajapati commented: ++ +15
Mitja Bonca 557 Nearly a Posting Maven

Yep.. do it this way:

Public Sub New()
	'in  constructor or in load event (before showing actually):
	comboBox1.DataSource = New BindingSource(table1, Nothing)
	comboBox1.DisplayMember = "Catname"
	comboBox1.ValueMember = "Carid"
	'subscribe to an event:
	comboBox1.SelectedIndexChanged += New EventHandler(AddressOf comboBox1_SelectedindexChanged)
End Sub

'event:
Private Sub comboBox1_SelectedindexChanged(sender As Object, e As EventArgs)
	'get value of comboBox1:
	Dim drv As DataRowView = DirectCast(comboBox1.SelectedItem, DataRowView)
	Dim value As Integer = Convert.ToInt32(drv("Catid"))

	'now get new data from datatable2 (or from dataSet):
	Dim rows As DataRow() = table2.[Select]("Catid = '" & value & "'")
	Dim tableSelected As DataTable = table2.Clone()
	For Each row As DataRow In rows
		tableSelected.ImportRow(row)
	Next

	'bind new table to comboBox2:
	combobox2.DataSource = Nothing
	comboBox2.DataSource = New BindingSource(tableSelected, Nothing)
	comboBox2.DisplayMember = "preasset"
	comboBox2.ValueMember = "Subcat"
	'or what ever use for the value (if needed, but I guess you wont need it at all).
End Sub

Note: table1 represents your dataTable1, and table2 is DataTable2 (like you said).

Mitja Bonca 557 Nearly a Posting Maven

What do you mean exactly? I dont understand your question.

Mitja Bonca 557 Nearly a Posting Maven

To get a week number of the month you can do:

//in your method:
DateTime time = DateTime.Now;
int weekNumber = GetWeekOfMonth(time); //calling a method

        public static int GetWeekOfMonth(DateTime date)
        {
            DateTime beginningOfMonth = new DateTime(date.Year, date.Month, 1);

            while (date.Date.AddDays(1).DayOfWeek != CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek)
                date = date.AddDays(1);

            return (int)Math.Truncate((double)date.Subtract(beginningOfMonth).TotalDays / 7f) + 1;
        }
ddanbe commented: Nice addition! +14
Mitja Bonca 557 Nearly a Posting Maven

Hi,
you want to update what? Database or datagridview?
This code looks like more to be use to update database, just that UPDATE statement isnt sufficient enough).
Is has to be like: "UPDATE TableName SET Field1 = @field1, Field2 = @field2 WHERE ColditionColumn = @field3"

Am I right?

Mitja Bonca 557 Nearly a Posting Maven

I dount. I dont think so.
But if this is only the look you want do have (so from 2 forms will be look like 1), you can do the following:
- put all the controls on each form intoa userControl (together with the code of course)
- create a third form (new one) and use those two userControls on it!

I cant see any other reasonable solution to this. I havent even heard of it before.

Mitja Bonca 557 Nearly a Posting Maven

In comparing, you can only use two types of operators: != (not equal) and == (equl).
You cannot use <=, >= becuase these are for numeric comparations.

Or an example from Adapost (which in my opinion is a great one - HashCode is some of a unique key of the value), which you can write like:

int a = 5;
int b = 5;
if (a.GetHashCode().Equals(b.GetHashCode()))
{ 
   //equal      
}

Or Momerath`s example code (in upper post).
Or:

if(o1 == o2)
{
    //objects same
}
else
{
    //different
}
Mitja Bonca 557 Nearly a Posting Maven

- Illustratec C# 2008 (for beginners)
- C# in depth 2nd Edition
- C# 2008 (or 2010) Step by Step)
- C# 4.0 In a Nutshell

but there is plenty of books, especially on amazon.com
Depends what you would like to lean. Or OOP, or databases, of web prgramming, or..

Mitja Bonca 557 Nearly a Posting Maven

hehe, indeed! You must delete that semicolon there!! Didnt see it.
Must be something wrong with the webiste - it wasnt responcive for a while.
Sorry for that.

Mitja Bonca 557 Nearly a Posting Maven

hehe, indeed! You must delete that semicolon there!! Didnt see it.

Mitja Bonca 557 Nearly a Posting Maven

hehe, indeed! You must delete that semicolon there!!

Mitja Bonca 557 Nearly a Posting Maven

Getting data (all of it):
1. Create a DataTable (to later get the data out of dataBase)
2. Connect to the dataBase with an appropriate connection string (using Connection class)
3. Fill dataTable, using DataAdapter class
------------

Showing data (one by one question):
4. Loop through the rows of dataTable, starting from 0 row index (1st row) and show the question from it (so from 1st row).
5. If some conditions are meat (correct answer on the question), go to next Question in "currentRow + 1", so to next row.

PS: I hope you have answers in the dataTable as well.

Can you do that, or you need any help?

Mitja Bonca 557 Nearly a Posting Maven

do it:

using System;

namespace hahahahahahahahaha
{
	class Program
	{
		public static void Main(string[] args)
		{
		       constructor1  obj = new constructor1();
                       Console.ReadLine(); //need to insert this line of code to show console!
		}
	}
	
	
	public class constructor1
	{
		public constructor1();
		{			
			Console.WriteLine("hahahaha");			
		}
	}	
}
Mitja Bonca 557 Nearly a Posting Maven

Here is what you can do:
I would use a backgroundworker, and do the download work in it:

private delegate void DownloadDelegate(string msg);
        private BackgroundWorker bgv;

        public Form1()
        {
            InitializeComponent();
            //create bgv:
            bgv = new BackgroundWorker();
            bgv.ProgressChanged += new ProgressChangedEventHandler(bgv_ProgressChanged);
            bgv.DoWork += new DoWorkEventHandler(bgv_DoWork);
            bgv.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgv_RunWorkerCompleted);

            //label will be used as a note of a progress
            label1.Text = "";

            //creating columns:
            DataGridViewButtonColumn btnColumn = new DataGridViewButtonColumn();
            btnColumn.HeaderText = "Dowload";
            btnColumn.Name = "column2";
            btnColumn.Text = "download";
            btnColumn.UseColumnTextForButtonValue = true;

            dataGridView1.Columns.Add("column1", "Text Name");
            dataGridView1.Columns.Add(btnColumn);

            //adding some example rows:
            for (int i = 1; i < 6; i++)
                dataGridView1.Rows.Add("Test number " + i);

            //adding event:
            dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == dataGridView1.Columns["column2"].Index)
            {
                //disable dgv until download runs our:
                //dataGridView1.Enabled = false;
                bgv.RunWorkerAsync();
                //disable dgv:
                dataGridView1.Enabled = false;
            }
        }

        void bgv_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (!(e.Error == null))
                label1.Text = "Error: " + e.Error.Message;
            else
            {
                label1.Text = "Done!";
                //enable dgv:
                dataGridView1.Enabled = true;
            }
        }

        void bgv_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            worker.WorkerReportsProgress = true;
            worker.WorkerSupportsCancellation = true;

            //
            //THIS IS WHERE YOU PUT YOUR DOWNLOAD CODE!!!
            //
            //this is only my example code of time consuming:
            int total = 50; //some variable
            for (int i = 0; i < total; i++)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                else
                    worker.ReportProgress((100 * i) / total);
                //stop a bit:
                System.Threading.Thread.Sleep(50);
            }
        }

        void bgv_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            label1.Text = " …
Mitja Bonca 557 Nearly a Posting Maven

Why would you do an even for some button inside other button? This makes no sence.
Events for all the button can be generated on the load time. Or when you create some button in the run time (afterwards).

If you still inisit you can do it:

private void button6_Click(object sender, EventArgs e)
        {
            //just make sure your button initialized on form!!
            this.button7.Click += new EventHandler(button7_Click);
            EvenArgs ee = new EventArgs();
            button7_Click(this.button7, ee); //this will fire button event!
        }
        private void button7_Click(object sender,EventArgs e)
        {
            MessageBox.Show("Button7 Clicked when ur pressing button6");
        }
Mitja Bonca 557 Nearly a Posting Maven

You have to add rows as well (every loop):

int clicks = 0;
        private void button4_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Add();
            dataGridView1.Rows[clicks].Cells["Author_Number"].Value = "Author " + (clicks + 1).ToString();
            dataGridView1.Rows[clicks].Cells["First_name"].Value = "fname";
            dataGridView1.Rows[clicks].Cells["Last_name"].Value = "lname";
            clicks++;
        }
Mitja Bonca 557 Nearly a Posting Maven

Hi, have you managed to salve the problem yet?

Mitja Bonca 557 Nearly a Posting Maven

This doesnt make any difference. Do you have any other code maybe, which would intentioanlly close your "WindowsForm"?

There`s got to be something, because form can close just by it self. Please double check whole code!!

Mitja Bonca 557 Nearly a Posting Maven

Would you mind showing us the code? I cannot know what can be wrong.

Mitja Bonca 557 Nearly a Posting Maven

It seems your connection string to the database is not correct. And as far as i can see you use mySql database (on phpmyadmin).
Try this form is connection string:

"server=localhost;user id=root;password=secret;database=yourDataBaseName;"
Mitja Bonca 557 Nearly a Posting Maven

DateTime column is causing the problems I would say. YOu only do "DateTime.Now" - no parsing to string.

btw, what error you get in catch Exception?

Mitja Bonca 557 Nearly a Posting Maven

I have showed you an example in some other of your thread!!

Mitja Bonca 557 Nearly a Posting Maven

And you can have private classes, no matter what Mitja says :)

Yes, only nested (I know that, but I actually dont use them - not yet).

Mitja Bonca 557 Nearly a Posting Maven

There is no private class and any sign of any property in your example. Private class does not exist at all (it cannnot).
Do you know what properties are? And what classes are for?

Mitja Bonca 557 Nearly a Posting Maven

Try with this:

bool bMaleSelected;
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = "9164";
            comboBox1.Items.AddRange(new string[] { "male", "female" });
            comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex > -1)
            {
                int intValue = 0;
                if (int.TryParse(textBox1.Text.Trim(), out intValue))
                {
                    if (comboBox1.SelectedItem.ToString() == "male")
                    {
                        if (!bMaleSelected)
                        {
                            textBox1.Text = (intValue + 1500).ToString();
                            bMaleSelected = true;
                        }
                    }
                    else if (comboBox1.SelectedItem.ToString() == "female")
                    {
                        if (bMaleSelected)
                        {
                            textBox1.Text = (intValue - 1500).ToString();
                            bMaleSelected = false;
                        }
                    }
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Or this was (this is what you wanted) using a new keyword on the method in Son`s class:

class Program
    {
        static void Main(string[] args)
        {
            Son p1 = new Son();
            p1.print();

            Father p2 = new Son();
            p2.print();
            
            //Hidden base class members can still be accessed from client code 
            //by casting the instance of the derived class to an instance of the base class.
            Father p3 = (Father)p1;
            p3.print();           

            Console.ReadLine();
        }
    }

    class Father
    {
        public virtual void print()
        {
            Console.WriteLine("Father");
        }
    }

    class Son : Father
    {
        public new void print()
        {
            Console.WriteLine("Son");
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

or you can use constructors, with base method to access to base constuctor:

class Program
    {
        static void Main(string[] args)
        {
            Son p1 = new Son();
            Father p2 = (Father)p1;
            Father p3 = new Father();
            Console.ReadLine();
        }
    }

    class Father
    {
        public Father()
        {
            Console.WriteLine("Father`s constructor");
        }
    }

    class Son : Father
    {
        public Son()
            : base()
        {
            Console.WriteLine("Son`s constructor");
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

AS Momerath stated, its an awkward example.
But you can use a base keyword to access members of the base class from within a derived class:

class Program
    {
        static void Main(string[] args)
        {
            Son p1 = new Son();
            Father p2 = (Father)p1;
            Father p3 = new Father();

            p1.print();
            p2.print();
            p3.print();
            Console.ReadLine();
        }
    }

    class Father
    {
        public virtual void print()
        {
            Console.WriteLine("Father");
        }
    }

    class Son : Father
    {
        public override void print()
        {
            base.print();
            Console.WriteLine("Son");
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

The easiest way is to fill DataTable (from dataBase). Then use DataSource property of listBox to bind data to it. Use DisplyMember to show the names, and Id for ValueMember.
So next is, when you click on the item (name) you get the id of person of selected item, and based on that, you can get all the other data of that person from dataTable.
Then you only pass these data (as an array of objects maybe) where ever you want ( to other form as you wanted).
Is this clear?

Mitja Bonca 557 Nearly a Posting Maven

About which details are you talking about? There is nothing like it.

Mitja Bonca 557 Nearly a Posting Maven

Here you have online converter.

ddanbe commented: Hey! Great tip! +14
Mitja Bonca 557 Nearly a Posting Maven

You have to create columns of listView to dataTable (with a bit of a List<T> help), then loop through the listView to fill dataTable:

'lets assume we have 3 column in listView!!

'get columns:
Dim listOfColumns As New List(Of String)()
For Each column As ColumnHeader In listView1.Columns
	listOfColumns.Add(column.ToString())
Next

'create DataTable:
Dim table As New DataTable("myTable")
For Each column As String In listOfColumns
	table.Columns.Add(column, GetType(String))
Next

'fill table with datafrom listView

Dim row As DataRow
Dim i As Integer = 0
For Each item As ListViewItem In listView1.Items
	row = table.NewRow()
	'define for each column in listView:
	row(listOfColumns(i)) = item.Text
	row(listOfColumns(i)) = item.SubItems(1).Text
	row(listOfColumns(i)) = item.SubItems(2).Text
	table.Rows.Add(row)
Next
Mitja Bonca 557 Nearly a Posting Maven

Why would you do a for loop? I dont see any reasonable reson why use it.
Please explain why would you use a for loop?

Mitja Bonca 557 Nearly a Posting Maven

Instead of while loop, better use abn if block. Because you want to go through the code only ones.
And there you can put an else block, which will be fired if no data will be found:

If dr.Read Then
	txtidno.Text = dr("ID_No")
	txtname.Text = dr("Borrower_Name")
	cbocourse.Text = dr("Course")
	txtcontactno.Text = dr("Contact_No")
	txtaddress.Text = dr("Address")
Else
	MessageBox.Show("No data found.")
End If
Mitja Bonca 557 Nearly a Posting Maven

Do you add object to array list like that:

ArrayList main = new ArrayList();
            main.Add("1,A");
            main.Add("2,A");
            main.Add("3,B");
Mitja Bonca 557 Nearly a Posting Maven

If I understood you, you want to load a picture into a pictureBox?
And the right one? Does the image has a name?

Mitja Bonca 557 Nearly a Posting Maven

Take a look at this example:

//your putputs to create dataTable:
            int ID = 1;
            string Reccurence = "Monthly";
            string DuePatten = "26";
            //if Duepattern is a string, I will change it to integer:
            int _DuePattern = int.Parse(DuePatten);

            DataTable table = new DataTable("myTable");
            table.Columns.Add("History_ID", typeof(int));
            table.Columns.Add("Date_Due", typeof(DateTime));

            DataRow row;
            if (Reccurence == "Monthly")
            {
                for (int i = 1; i <= 12; i++)
                {
                    DateTime date = new DateTime(DateTime.Now.Year, i, _DuePattern);
                    row = table.NewRow();
                    row["History_ID"] = ID;
                    row["Date_Due"] = date;
                    table.Rows.Add(row);
                }
            }
Mitja Bonca 557 Nearly a Posting Maven

Can you describe the problem a bit better, and what is it that you want?!
But as far as I understood, you get some data from DB:
ID=1
Reccurence = "Monthly"
DuePatten = "26"

Now based on this you want to create an array of dates, am I right?
What do you want dateTime value or strings? If stirng, any special format?

Mitja Bonca 557 Nearly a Posting Maven

Hi,
sorry, but I dont really understand what you are saying.
Would you please do a bit better explanation to the problem you are facing?
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

Dont complicate things. Do it like this:

Dim conn As New SqlConnection("connString")
Dim da As New SqlDataAdapter()
Dim table As New DataTable()
da.SelectCommand.CommandText = "your select query"
da.SelectCommand.Connection = conn
da.Fill(table)

And you dont have to use DataSet,if you only have one DataTable. Instead you use DataTable, as I showed in example.

Mitja Bonca 557 Nearly a Posting Maven

If a label enters another label.

What do you mean exactly?

Mitja Bonca 557 Nearly a Posting Maven

Use this pattern to all:

Dim a As Decimal = 6.25D
//pattern:
Dim fraction As Decimal = a - CInt(Math.Truncate(a))
a = a - fraction + (0.95D)
Mitja Bonca 557 Nearly a Posting Maven

Or:

Process process = new Process();
     process.StartInfo.FileName = @"notepad.exe";
     process.EnableRaisingEvents = true;
     process.Start();
Mitja Bonca 557 Nearly a Posting Maven

Maybe this way?:

System.Diagnostics.Process myprocess = System.Diagnostics.Process.Start("notepad.exe");
Mitja Bonca 557 Nearly a Posting Maven
mysqlda.UpdateCommand.Parameters.Add("@Price", MySqlDbType.Decimal ,10,2, "Price");

The 3rd parameter in the Add() method is the Size, and its must me an integer. So no commas in between. You dont specify and such thing as in the database, where you specify the number of decimals (like 10, 2 - 10 numbers lenght,and precision of these 2 decimals).
Here you only specify the size of the value).
It represents The maximum size, in bytes, of the data within the column.
This parameter is not so important, because Size affects only the input value of a parameter. Return values and output parameters are not affected by this property.

You can set the size to -1, to ensure that you are getting the entire data from the backend without truncation.

Here is what you can all set for particular parameter:

SqlParameter myParameter = new SqlParameter("@Price", SqlDbType.Decimal);
    myParameter.Value = /some value
    myParam.Size = -1; //or you can set it to 5
    myParameter.Precision = 8;
    myParameter.Scale = 4;

This is only to show you how you can set parameters for a SqlParameter class.
You can do something like this:

mysqlda.UpdateCommand.Parameters.Add("@Price", MySqlDbType.Decimal ,5, "Price");
Mitja Bonca 557 Nearly a Posting Maven

Show us full code.. the connection instantiation, and its connection string.

Mitja Bonca 557 Nearly a Posting Maven

alt + w (in european keyboards)

Mitja Bonca 557 Nearly a Posting Maven

or:

Dim letters As Char() = textBox1.Text.ToCharArray()
Mitja Bonca 557 Nearly a Posting Maven

Hi, check for solution here.

Mitja Bonca 557 Nearly a Posting Maven

Did you thing using only:

//now u can save changes to back end with
 da.Update(ds);

will save the changes to the dataBase? Nope. YOu need some other code for UPDATE as well.
What does the SqlCommand for Update look like? I see the command but I don't see any SqlText, that's what you're missing.

You need to define what .Update does by setting .UpdateCommand property on the SqlDataAdapter

This link gives a pretty good breakdown on how to go about it here.