|
|
|
ถามเรื่อง Treeview กับ Listview ค่ะ รบกวนคนรู้ช่วยบอกทีค่ะ |
|
|
|
|
|
|
|
ให้ดีลอง Copy Code มาด้วยครับ เผื่ออาจจะมีสมาชิกคนอื่น ๆ ช่วยได้ครับ
|
|
|
|
|
Date :
2012-03-10 08:59:36 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using ContentforMobileLearning.DataObjects;
namespace ContentforMobileLearning
{
public partial class CreateContent : Form
{
#region Constructor
public CreateContent()
{
InitializeComponent();
treeView1.Enter += new EventHandler(treeView1_Enter);
treeView1.Click += new EventHandler(treeView1_Click);
treeView1.DoubleClick += new EventHandler(treeViwe1_DoubleClick);
Content();
Page();
i++;
treeView1.ExpandAll();
}
#endregion
#region - File -
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void openToolStripMenuItem1_Click(object sender, EventArgs e)
{
}
private void closeProjectToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("จบการทำงาน", "Exit", MessageBoxButtons.YesNo) == DialogResult.Yes)
this.Close();
}
#endregion
#region - Content Builder -
private void addNewPageToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void deletePageToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void importMultimediaFileToolStripMenuItem_Click(object sender, EventArgs e)
{
var openFile = new OpenFileDialog();
openFile.Multiselect = true;
openFile.Filter = "All files|*.*";
openFile.RestoreDirectory = true;
if (openFile.ShowDialog() == DialogResult.OK)
{
if (openFile.FileNames != null)
{
for (int i = 0; i < openFile.FileNames.Length; i++)
{
addImage(openFile.FileNames[i]);
}
}
else
addImage(openFile.FileName);
}
listView1.View = View.LargeIcon;
imageList1.ImageSize = new Size(64, 64);
listView1.LargeImageList = imageList1;
}
private void removeToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.SuspendLayout();
if (MessageBox.Show("Are you sure you want to remove", "Remove item", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
foreach (ListViewItem item in listView1.SelectedItems)
{
listView1.Items.Remove(item);
}
}
listView1.ResumeLayout(true);
}
private void exportToXMLToolStripMenuItem_Click(object sender, EventArgs e)
{
var saveFile = new SaveFileDialog();
saveFile.FileName = "";
saveFile.Filter = "XML Files|*.xml|All Files|*.*";
if (saveFile.ShowDialog() == DialogResult.OK)
{
WriteXml write = new WriteXml();
write.serializeXml(treeView1, saveFile.FileName);
}
}
private void importFromXMLToolStripMenuItem_Click(object sender, EventArgs e)
{
var openFile = new OpenFileDialog();
openFile.FileName = "";
openFile.Filter = "XML Files|*.xml|All Files|*.*";
if (openFile.ShowDialog(this) == DialogResult.OK)
{
ReadXml read = new ReadXml();
read.deserializeXml(openFile.FileName, treeView1);
}
}
#endregion
#region - Emulator -
private void playContentToolStripMenuItem_Click(object sender, EventArgs e)
{
PlayContent f2 = new PlayContent(this);
f2.ShowDialog();
}
#endregion
#region - Help -
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
About f3 = new About(this);
f3.ShowDialog();
}
#endregion
#region - Treeview -
private void cmnuAddNode_Click(object sender, EventArgs e)
{
Page();
i++;
treeView1.ExpandAll();
}
private void cmnuRemoveNode_Click(object sender, EventArgs e)
{
treeView1.SelectedNode.Remove();
}
private void treeViwe1_DoubleClick(object sender, EventArgs e)
{
treeView1.LabelEdit = true;
treeView1.SelectedNode.BeginEdit();
}
private void treeView1_Enter(object sender, EventArgs e)
{
treeView1.LabelEdit = false;
}
private void treeView1_Click(object sender, EventArgs e)
{
treeView1.LabelEdit = false;
}
public void Content()
{
ContentData data = new ContentData();
treeView1.Nodes.Add(data.Content);
treeView1.Nodes[0].Nodes.Add(data.ContentInformationt);
treeView1.Nodes[0].Nodes[0].Nodes.Add(data.ContentName);
treeView1.Nodes[0].Nodes[0].Nodes[0].Nodes.Add(data.Name);
treeView1.Nodes[0].Nodes[0].Nodes.Add(data.ContentDescription);
treeView1.Nodes[0].Nodes[0].Nodes[1].Nodes.Add(data.Description);
treeView1.Nodes[0].Nodes[0].Nodes.Add(data.ContentAuthor);
treeView1.Nodes[0].Nodes[0].Nodes[2].Nodes.Add(data.Author);
treeView1.Nodes[0].Nodes[0].Nodes.Add(data.ContentDate);
treeView1.Nodes[0].Nodes[0].Nodes[3].Nodes.Add(data.Date);
}
int i = 1;
private void Page()
{
ContentPage page = new ContentPage();
treeView1.Nodes[0].Nodes.Add(page.ContentPages);
treeView1.Nodes[0].Nodes[i].Nodes.Add(page.ContentSequence);
treeView1.Nodes[0].Nodes[i].Nodes[0].Nodes.Add("1");
treeView1.Nodes[0].Nodes[i].Nodes.Add(page.ContentPageType);
treeView1.Nodes[0].Nodes[i].Nodes[1].Nodes.Add(page.PageType);
treeView1.Nodes[0].Nodes[i].Nodes.Add(page.ContentPageDescription);
treeView1.Nodes[0].Nodes[i].Nodes[2].Nodes.Add(page.PageDescription);
treeView1.Nodes[0].Nodes[i].Nodes.Add(page.ContentVideoFileName);
treeView1.Nodes[0].Nodes[i].Nodes[3].Nodes.Add(page.VideoFileName);
treeView1.Nodes[0].Nodes[i].Nodes.Add(page.ContentImageFileName);
treeView1.Nodes[0].Nodes[i].Nodes[4].Nodes.Add(page.ImageFileName);
treeView1.Nodes[0].Nodes[i].Nodes.Add(page.ContentSoundeFileName);
treeView1.Nodes[0].Nodes[i].Nodes[5].Nodes.Add(page.SoundeFileName);
}
#endregion
#region - Listview -
private void delectToolStripMenuItem_Click(object sender, EventArgs e)
{
listView1.SuspendLayout();
if (MessageBox.Show("Are you sure you want to remove", "Remove item", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
foreach (ListViewItem item in listView1.SelectedItems)
{
listView1.Items.Remove(item);
}
}
listView1.ResumeLayout(true);
}
int baseValue = 0;
private void addImage(string imageToLoad)
{
try
{
if (imageToLoad != "")
{
imageList1.Images.Add(Image.FromFile(imageToLoad));
listView1.BeginUpdate();
listView1.Items.Add(imageToLoad, baseValue++);
listView1.EndUpdate();
}
}
catch
{
MessageBox.Show("This is not an image file", "Not Image");
}
}
#endregion
}
}
|
|
|
|
|
Date :
2012-03-10 18:07:14 |
By :
petit_fern |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ContentforMobileLearning.DataObjects
{
class ContentData
{
private String content = "CONTENT";
public string Content
{
get { return content; }
set { content = value; }
}
private String contentInformationt = "CONTENT_INFORMATION";
public string ContentInformationt
{
get { return contentInformationt; }
set { contentInformationt = value; }
}
private String contentName = "NAME";
public string ContentName
{
get { return contentName; }
set { contentName = value; }
}
private String name = "------";
public string Name
{
get { return name; }
set { name = value; }
}
private String contentDescription = "DESCRIPTION";
public string ContentDescription
{
get { return contentDescription; }
set { contentDescription = value; }
}
private String description = "------";
public string Description
{
get { return description; }
set { description = value; }
}
private String contentAuthor = "AUTHER";
public string ContentAuthor
{
get { return contentAuthor; }
set { contentAuthor = value; }
}
private String author = "------";
public string Author
{
get { return author; }
set { author = value; }
}
private String contentDate = "DATE";
public string ContentDate
{
get { return contentDate; }
set { contentDate = value; }
}
private String date = "------";
public string Date
{
get { return date; }
set { date = value; }
}
}
}
|
|
|
|
|
Date :
2012-03-10 18:07:37 |
By :
petit_fern |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ContentforMobileLearning.DataObjects
{
public class ContentPage
{
private String contentPage = "CONTENT_PAGE";
public string ContentPages
{
get { return contentPage; }
set { contentPage = value; }
}
private String contentSequence = "SEQUENE";
public string ContentSequence
{
get { return contentSequence; }
set { contentSequence = value; }
}
/*public int sequence ;
public int Sequence
{
get { return sequence; }
set { sequence = value; }
}*/
private String contentPageType = "PAGR_TYPE";
public string ContentPageType
{
get { return contentPageType; }
set { contentPageType = value; }
}
private String pageType = "------";
public string PageType
{
get { return pageType; }
set { pageType = value; }
}
private String contentPageDescription = "PAGR_DESCRIPTION";
public string ContentPageDescription
{
get { return contentPageDescription; }
set { contentPageDescription = value; }
}
private String pageDescription = "------";
public string PageDescription
{
get { return pageDescription; }
set { pageDescription = value; }
}
private String contentVideoFileName = "VIDEO_FILE_NAME";
public string ContentVideoFileName
{
get { return contentVideoFileName; }
set { contentVideoFileName = value; }
}
private String videoFileName = "*.mp4";
public string VideoFileName
{
get { return videoFileName; }
set { videoFileName = value; }
}
private String contentImageFileName = "IMAGE_FILE_NAME";
public string ContentImageFileName
{
get { return contentImageFileName; }
set { contentImageFileName = value; }
}
private String imageFileName = "*.jpg";
public string ImageFileName
{
get { return imageFileName; }
set { imageFileName = value; }
}
private String contentSoundeFileName = "SOUND_FILE_NAME";
public string ContentSoundeFileName
{
get { return contentSoundeFileName; }
set { contentSoundeFileName = value; }
}
private String soundeFileName = "*.mp3";
public string SoundeFileName
{
get { return soundeFileName; }
set { soundeFileName = value; }
}
}
}
|
|
|
|
|
Date :
2012-03-10 18:07:59 |
By :
petit_fern |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|