Thursday 31 January 2013

concatenate two strings in crystal report


Field exporer---- Formula field------create new


{Employee.employeeFirstName}+" "+{Employee.employeeMiddleName}+" "+{Employee.employeeLastName}

Tuesday 29 January 2013

move listbox items to another listbox in c#

// all items moves from left listbox to right


int count = listBox1.Items.Count;//assigning items in listbox it into count variable
            if (count != 0)//checking the conditions
            {
                for (int i = 0; i < count; i++)
                {
                    listBox2.Items.Add(listBox1.Items[i]);
                }
            }

            listBox1.Items.Clear();//clear the listbox after transfering records.


//only selected item move to right listbox


if (listBox1.SelectedIndex > -1)
            {
                listBox2.Items.Add(listBox1.SelectedItem);//transfer records from listbox1 to Listbox2 on select records..
                listBox1.Items.Remove(listBox1.SelectedItem);

            }

//only selected item move to left listbox


if (listBox2.SelectedIndex > -1)
            {
                listBox1.Items.Add(listBox2.SelectedItem);
                listBox2.Items.Remove(listBox2.SelectedItem);
            }

// all items moves from right listbox to left


int count = listBox2.Items.Count;
            if (count != 0)
            {
                for (int i = 0; i < count; i++)
                {
                    listBox1.Items.Add(listBox2.Items[i]);
                }
            }
            listBox2.Items.Clear();


display data in listview c#


string SQL = "SELECT departmentName FROM Department";
            source.View = View.Details;

            OleDbConnection con = new OleDbConnection(connectionString);
            OleDbCommand cmd = new OleDbCommand(SQL, con);
            OleDbDataReader r = null;

            con.Open();
            r = cmd.ExecuteReader();
            for (int i = 0; i <= r.FieldCount - 1; i++)
            {
                source.Columns.Add("Column " + (i + 1).ToString(), 200, HorizontalAlignment.Left);
            }
            while (r.Read())
            {
                ListViewItem lvItem = new ListViewItem(r[0].ToString());
                for (int i = 1; i <= r.FieldCount - 1; i++)
                {
                    lvItem.SubItems.Add(r[i].ToString());
                }
                source.Items.Add(lvItem);
            }
            con.Close();

display data in listbox c#


private void displayDataInListBox()
        {
            try
            {
                OleDbConnection connection = new OleDbConnection(connectionString);
                OleDbDataAdapter da = new OleDbDataAdapter();
                connection.Open();
                OleDbDataReader Dr;
                OleDbCommand command1 = new OleDbCommand("SELECT departmentName FROM Department", connection);
                command1.ExecuteNonQuery();
                Dr = command1.ExecuteReader();
                listBox1.Items.Clear();
                while (Dr.Read())
                {

                    listBox1.Items.Add(Dr.GetString(0).ToString());

                }
                Dr.Close();
            }
            catch (OleDbException ex)
            {
                MessageBox.Show(ex.Message);
            }
          
        }

how to create multiple textbox at runtime in c#.net


public void createTextBox()
        {
            TextBox[] txtTextBox = new TextBox[10];

            for (int u = 0; u < txtTextBox.Count(); u++)
            {
                txtTextBox[u] = new TextBox();
            }
            int i = 0;
            foreach (TextBox txt in txtTextBox)
            {
                string name = "TextBoxName" + i.ToString();

                txt.Name = name;
                txt.Text = name;
                txt.Location = new Point(0, 32 + (i * 28));
                txt.Visible = true;
                this.Controls.Add(txt);
                i++;
            }
        }