C# problems
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: C# problems

  1. #1
    Join Date
    Apr 2010
    Posts
    9

    C# problems

    Visual Studio 2005 .net 2.0
    Ok so I am trying to get this code so it will only allow for me to deleat only one item at a time and not every single itme. I relly dont know where to look for it. This is my first time in C# and working on mobil apps so I relly am lost here I dont really know where to start.
    Here is the main code
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace ToDoListWM5
    {
    public partial class Form1 : Form
    {

    private Model toDoListModel;


    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    toDoListModel = new Model();
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    }

    private void menuItem2_Click(object sender, EventArgs e)
    {
    switch (((MenuItem)sender).Text)
    {
    case "Delete":
    {
    toDoListModel.DeleteToDoListItems(this.deleteToDoItemsView1.ViewItemsToDelete);
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "Add";
    this.menuItem2.Text = "Delete";
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    break;
    }
    case "OK":
    {
    toDoListModel.AddToDoListItem(this.addToDoItemView1.ViewItemToAdd);
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "Add";
    this.menuItem2.Text = "Delete";
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    break;
    }
    }
    }

    private void menuItem1_Click(object sender, EventArgs e)
    {
    switch (((MenuItem)sender).Text)
    {
    case "Add":
    {
    this.addToDoItemView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "BACK";
    this.menuItem2.Text = "OK";
    this.deleteToDoItemsView1.Visible = false;
    this.addToDoItemView1.Visible = true;
    break;
    }
    case "BACK":
    {
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "Add";
    this.menuItem2.Text = "Delete";
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    break;
    }
    }

    }




    }
    }

    and here is the deleat code

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;

    namespace ToDoListWM5
    {
    public partial class DeleteToDoItemsView : UserControl
    {

    private ToDoListDS.ToDoListDataTable viewData;

    private ToDoListDS.ToDoListDataTable viewItemsToDelete;

    public DeleteToDoItemsView()
    {
    InitializeComponent();
    viewItemsToDelete = new ToDoListDS.ToDoListDataTable();
    }

    public ToDoListDS.ToDoListDataTable ViewItemsToDelete
    {
    get
    {
    viewItemsToDelete.Clear();
    foreach (ListViewItem item in this.listView1.Items)
    {
    if (item.Checked)
    viewItemsToDelete.AddToDoListRow(item.Text);
    }
    return viewItemsToDelete;
    }
    }



    public ToDoListDS.ToDoListDataTable ViewData
    {
    set
    {
    viewData = value;
    this.listView1.Items.Clear();
    foreach (ToDoListDS.ToDoListRow row in viewData.Rows)
    {
    this.listView1.Items.Add(new ListViewItem(row.ToDoListItem));
    }
    }
    }


    }
    }


    thanks

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: C# problems

    Please use code tags so that you code is readable

    Code:
    [ code]your code here [ /code] (but then without the spaces)

  3. #3
    Join Date
    Apr 2010
    Posts
    9

    Re: C# problems

    Sorry I forgot to put the code thingys in
    Code:
     using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ToDoListWM5
    {
    public partial class Form1 : Form
    {
    
    private Model toDoListModel;
    
    
    public Form1()
    {
    InitializeComponent();
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
    toDoListModel = new Model();
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    }
    
    private void menuItem2_Click(object sender, EventArgs e)
    {
    switch (((MenuItem)sender).Text)
    {
    case "Delete":
    {
    toDoListModel.DeleteToDoListItems(this.deleteToDoItemsView1.ViewItemsToDelete);
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "Add";
    this.menuItem2.Text = "Delete";
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    break;
    }
    case "OK":
    {
    toDoListModel.AddToDoListItem(this.addToDoItemView1.ViewItemToAdd);
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "Add";
    this.menuItem2.Text = "Delete";
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    break;
    }
    }
    }
    
    private void menuItem1_Click(object sender, EventArgs e)
    {
    switch (((MenuItem)sender).Text)
    {
    case "Add":
    {
    this.addToDoItemView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "BACK";
    this.menuItem2.Text = "OK";
    this.deleteToDoItemsView1.Visible = false;
    this.addToDoItemView1.Visible = true;
    break;
    }
    case "BACK":
    {
    this.deleteToDoItemsView1.ViewData = toDoListModel.ToDoListViewData;
    this.menuItem1.Text = "Add";
    this.menuItem2.Text = "Delete";
    this.deleteToDoItemsView1.Visible = true;
    this.addToDoItemView1.Visible = false;
    break;
    }
    }
    
    }
    
    
    
    
    }
    }
    
    //and here is the deleat code
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ToDoListWM5
    {
    public partial class DeleteToDoItemsView : UserControl
    {
    
    private ToDoListDS.ToDoListDataTable viewData;
    
    private ToDoListDS.ToDoListDataTable viewItemsToDelete;
    
    public DeleteToDoItemsView()
    {
    InitializeComponent();
    viewItemsToDelete = new ToDoListDS.ToDoListDataTable();
    }
    
    public ToDoListDS.ToDoListDataTable ViewItemsToDelete
    {
    get
    {
    viewItemsToDelete.Clear();
    foreach (ListViewItem item in this.listView1.Items)
    {
    if (item.Checked)
    viewItemsToDelete.AddToDoListRow(item.Text);
    }
    return viewItemsToDelete;
    }
    }
    
    
    
    public ToDoListDS.ToDoListDataTable ViewData
    {
    set
    {
    viewData = value;
    this.listView1.Items.Clear();
    foreach (ToDoListDS.ToDoListRow row in viewData.Rows)
    {
    this.listView1.Items.Add(new ListViewItem(row.ToDoListItem));
    }
    }
    }
    
    
    }
    }

  4. #4
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: C# problems

    Ninja,

    A few simple guidelines to help you get more out of the people on here.

    1. Welcome.
    2. When you post, use a subject that describes your actual problem. Imagine if every thread on this forum's subject was "C# problems" !!
    3. Just extract the relevent code where the problem lies.
    4. Explain which bit you do not understand and what you have tried so far.
    5. Try putting in the code tags again and making sure your code is tabbed correctly. I believe you just copied and pasted it from this thread, which was not formatted. Re-copy/paste it from Visual Studio...
    Last edited by rliq; April 5th, 2010 at 07:32 PM.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  5. #5
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: C# problems

    Quote Originally Posted by dannystommen View Post
    Please use code tags so that you code is readable

    Code:
    [ code]your code here [ /code] (but then without the spaces)
    Danny... We are always telling people this, we need to come up with a standard sentence!!
    Maybe that above sentence could be a [TAG] itself!
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,254

    Re: C# problems

    Quote Originally Posted by rliq View Post
    Danny... We are always telling people this, we need to come up with a standard sentence!!
    Maybe that above sentence could be a [TAG] itself!
    What we need are quick links that we can pick from a menu.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center