Click Here

what i want is that when i write any thing on the richtextbox it appear on cell Text. I have found some codes on the internet but i don't know whats wrong:

for (int i = 0; i < richTextBox1.Lines.Length; i++)
{
   ListViewItem lvi = new ListViewItem(i.ToString());
   lvi.SubItems.Add(richTextBox1.Lines[i]);
   listView1.Items.Add(lvi);
}
///PS -- Its for two columns 

The other thing, I post Numberupdown item and i want to appear the time on it and on the cell time like this ""HH:MM:SS / 00:00:00"" so i control it by arrow

So, any ideas guys ?
P.S. I know that i can do this with DataGridVeiw but i want to learn something new

Recommended Answers

All 4 Replies

Here's an answer to "the other thing". Instead of NumericUpDown control you can customize DateTimePicker control

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "HH:MM:ss";
dateTimePicker1.ShowUpDown = true;

And here's for the first part of the question

private void button1_Click(object sender, EventArgs e)
{
    listView1.View = View.Details;
    // Add two columns first. Here column headers have an optional width
    listView1.Columns.Add("NO", 80);
    listView1.Columns.Add("Text", 250);
    // Add data items for two columns to listview control
    for (int i = 0; i < richTextBox1.Lines.Length; i++)
    {
        ListViewItem lvi = new ListViewItem(i.ToString());
        lvi.SubItems.Add(richTextBox1.Lines[i]);
        listView1.Items.Add(lvi);
    }
}

HTH

Thank you teme for you reply. I did what you say and it wrok and not ^-^
Click Here
The DateTimePicker it didn't work at all - I do all what i could to make it run but it appear only the "Mare, 17,2015".
and the the second code have some problem.

It's my mistake that i didn't explain it good. what i'm doing is a small program deal with subtitles (( film subtitle )) the problem is with this from of the subtitle ((listview)) and time (( the time box )) and Richtextbox . look to this image and you will understand me
Click Here

Here's a more complete code. Initializing controls should be done only once and before you do anything else. I added private void InitForm() which handles initialization when the (main) form is created. I also made the "NO"-field to use a global variable, I think that's what you want.

So here's the code with a lot of comments :)

    public Form1()
    {
        InitializeComponent(); // This line is generated by Visual Studio, do not remove it!
        // 
        InitForm(); // Here's the call to form's custom initialization
    }

    // Class variable(s)
    private int subTitleLineNumber;

    /// <summary>
    /// Set up main form and controls. Initialize global/class variables
    /// </summary>
    private void InitForm()
    {
        // Customize datetimepicker control
        dateTimePicker1.Format = DateTimePickerFormat.Custom;
        dateTimePicker1.CustomFormat = "HH:mm:ss"; // Notice that mm has to be lower case for minutes
        dateTimePicker1.ShowUpDown = true;
        dateTimePicker1.Text = "00:00:00"; // Display "zero time". Remove this line if not needed

        // Customize listview control
        listView1.View = View.Details;
        // Add two columns first. Here column headers have an optional width
        // 
        listView1.Columns.Add("NO", 80);
        listView1.Columns.Add("Text", 250);

        // Richtextbox control. Just make sure it's empty
        richTextBox1.Clear();

        // Initialize variable(s)
        subTitleLineNumber = 0;
    }

    /// <summary>
    /// Button1 moves lines from the rt-box to listview i.e. updates listview
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {
        ListViewItem newLineObject;
        string[] newLineStrings = new string[2]; // For two columns!

        // Add data items for two columns from rt-box to listview control
        foreach (string line in richTextBox1.Lines)
        {
            subTitleLineNumber++; // Increment line number
            newLineStrings[0] = subTitleLineNumber.ToString(); // First item is line number
            newLineStrings[1] = line; // Second item is a text line from the rt-box
            newLineObject = new ListViewItem(newLineStrings); // Create a new line to listview from the string array
            listView1.Items.Add(newLineObject); // Add new line to listview control
        }
        //richTextBox1.Clear(); // Uncomment this line if you want to clear the rt-box
    }

HTH

Thank you man, its OK, not the same what i want but close to it.

Thank you man for what you did for me and the world ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.