Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > C# WinApp สอบถามเรื่อง การสร้าง Usercontrol อยากทราบ Event ของ DataGridView ครับ


 

[.NET] C# WinApp สอบถามเรื่อง การสร้าง Usercontrol อยากทราบ Event ของ DataGridView ครับ

 
Topic : 124879



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook


จากกระทู้นี้ครับ
https://www.thaicreate.com/dotnet/forum/124690.html

และรูปนี้

doc

ผมไม่แน่ใจว่าจะสื่อปัญหาถูกไม๊(เพราะตอนนี้ผมก็งงกับปัญหาเช่นกัน)
คือถ้าจากโค้ด
Code (C#)
1.void browseButton_Click(object sender, EventArgs e)
2.       {
3.           ..................
4.           ...........................
5.       }


ผมอยากเอาไปใช้งานในรูปแบบ Event ของ DataGridView ครับ

คือปัญหาเกิดจาก เวลา user คลิกปุ่มเลือกไฟล์ แล้ว
ผมหา Event ของ DataGridView ที่ใช้งานไม่เจอ

Code (C#)
01.private void doncument_listDetailDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
02.        {
03.            if (e.ColumnIndex == 3)
04.                MessageBox.Show("3 5555");
05.        }
06.private void doncument_listDetailDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
07.        {
08.           /* if (e.ColumnIndex == 3)
09.            {
10.                MessageBox.Show("3");
11.                if (System.IO.Path.GetDirectoryName((string)doncument_listDetailDataGridView[1, e.RowIndex].Value) != TORServices.PathFile.PathData.Path_Document)
12.                {
13.                    System.IO.File.Move((string)doncument_listDetailDataGridView[1, e.RowIndex].Value, TORServices.PathFile.PathData.Path_Document + "\\" + System.IO.Path.GetFileName((string)doncument_listDetailDataGridView[1, e.RowIndex].Value));
14.                    doncument_listDetailDataGridView[1, e.RowIndex].Value = TORServices.PathFile.PathData.Path_Document + "\\" + System.IO.Path.GetFileName((string)doncument_listDetailDataGridView[1, e.RowIndex].Value);
15.                    MessageBox.Show("" + doncument_listDetailDataGridView[1, e.RowIndex].Value);
16.                }
17. 
18.            }*/
19.        }


แล้วใน CellEndEdit ก็ไม่ได้เช่นกัน
เท่าที่ผมเดา คือ browseButton_Click ซึ่งไม่ใช่ Event ของ DataGridView
พอคลิกเสร็จเรียบร้อย DataGridView จึงไม่มีอะไรตอบรับ

ผมอยากได้ Event ที่ DataGridView ตอบรับการคลิกของปุ่มครับ
ว่า ฉันคลิกแล้วนะ อะไรประมาณนี้ครับ

ปล.ผมยังไม่รู้ว่าผมมาถูกทางรึยังนะครับ 5555



Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x), Windows

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-10-07 16:23:15 By : lamaka.tor View : 2696 Reply : 35
 

 

No. 1



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ต่อเรื่องการทำงานกับไฟล์ครับ

ไม่รู้ผมคิดไปเองหรือว่าท่านอื่นเจอปัญหาแบบผมไม๊
วันนี้มานั่งทำเกียวกับไฟล์เอกสารของ หน่วยควบคุมเลยมานั่งๆคิดๆว่า

1.กรณีเราเลือกไฟล์มาแล้วเช่น X:\xxx\xx.doc แต่เราก็อยากให้เอาไปไว้ใน โฟลเดอร์จัดเก็บ X:\1311
ส่วนใหญ่ ท่านๆจะ copy หรือ move แล้วควรจะทำเลยหรือรอทำตอน save data

2. จากข้อ 1. ถ้า X:\1311 มีไฟล์อยู่แล้ว เราควรจะตัดสินยังไงครับ รึปล่อยให้ user จัดการ rename,overwrite,not move ฯลฯ เอง

3. ข้อคิดในการจัดการกับไฟล์ซ้ำ แต่อยู่คนละโฟลเดอร์ ครับ ควรทำยังไง

คิดไปคิดมาสงสัยอาจจะต้องเพิ่ม คลาส เกี่ยวกับไฟล์ อีกรึป่าวก็ไม่รู้ครับ
ท่าทางช่วงนี้จะเล่นเหล้าขาวหนักไปหน่อย สมองเริ่มจะ ตีบตันตื้อตึงตุนโตงเตง ไปหมดแล้ว 555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 16:33:38 By : lamaka.tor
 

 

No. 2



โพสกระทู้ ( 345 )
บทความ ( 2 )



สถานะออฟไลน์


คลิกปุ่ม Button จาก Cell(3) หลังจากดึงมาเสร็จให้ทำคำสั่งต่อไปใช่ไหมครับ ถ้าใช้


Code (VB.NET)
01.using Microsoft.VisualBasic;
02.using System;
03.using System.Collections;
04.using System.Collections.Generic;
05.using System.Data;
06.using System.Diagnostics;
07.using System.ComponentModel;
08.using System.Drawing;
09.using System.Linq;
10.using System.Text;
11.using System.Windows.Forms;
12.public class Form1
13.{
14.    private Button btnSelector = new Button();
15.    //สร้าง Buttnon
16.    private int pCase;
17.    //สำหรับ เก็บส่วนของการเลือก Column
18. 
19.    private void SelectorClick(object sender, EventArgs e)
20.    {
21.        switch (pCase) {
22.            case 1:
23.                //value from dataGridView1_CellEnter
24.                if (true) {
25.                    MessageBox.Show("Show Dialog here!!");
26.                    break; // TODO: might not be correct. Was : Exit Select
27.                }
28.                break;
29.        }
30.    }
31. 
32.    private void CreateButton(ref Button myButton)
33.    {
34.        myButton.FlatStyle = FlatStyle.Flat;
35.        myButton.FlatAppearance.BorderSize = 0;
36.        myButton.Size = new Size(30, 19);
37.        myButton.ImageAlign = ContentAlignment.MiddleCenter;
38.        myButton.FlatAppearance.MouseDownBackColor = Color.Transparent;
39.        myButton.FlatAppearance.MouseOverBackColor = Color.Transparent;
40.        myButton.BackColor = Color.Transparent;
41.        //myButton.Image = Properties.resources.search3
42.        myButton.Image = Image.FromFile(FileSystem.CurDir() + "\\pic\\SearchBc.png");
43. 
44.        //กำหนดรูปภาพ
45.        myButton.Hide();
46.        myButton.Click += new EventHandler(this.SelectorClick);
47.        //--------------------------------------------
48.    }
49. 
50.    private void Form1_Load(System.Object sender, System.EventArgs e)
51.    {
52.        CreateButton(ref btnSelector);
53.        DataGridView1.Controls.Add(btnSelector);
54.    }
55. 
56.    private void DataGridView1_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
57.    {
58.        if (DataGridView1.Columns(e.ColumnIndex).Name == "Column1") {
59.            pCase = 1;
60.            Rectangle Loc = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
61.            int Wid = DataGridView1.CurrentCell.Size.Width;
62.            btnSelector.Location = new Point(Loc.X - 25 + Wid, Loc.Y);
63.            btnSelector.Show();
64.        }
65.    }
66. 
67.    private void DataGridView1_CellLeave(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
68.    {
69.        if (btnSelector.Focused != true) {
70.            btnSelector.Hide();
71.        }
72. 
73.    }
74.}


Code
https://www.thaicreate.com/community/vb-datagridview-textbox-button.html


ถ้าไม่ใช้ผมเข้าใจผิด


ประวัติการแก้ไข
2016-10-07 16:43:12
2016-10-07 16:45:46
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 16:42:40 By : guest
 

 

No. 3



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 2 เขียนโดย : guest เมื่อวันที่ 2016-10-07 16:42:40
รายละเอียดของการตอบ ::
Button ผมมีแล้วครับ

แต่ฝั่ง user เอามาใช้ไม่ได้ครับ

ผมแค่อยากให้ DataGridView1 มันรับรู้ข้อมูลมั่งอ่าครับ
คือผมใช้ทั้ง CellClick CellValueChanged หรือ CellEndEdit ก็ไม่เป็นมันหืออือกับ usercontrol ผมเลยครับ
แบบนี้ผมทำงานฝั่ง DataGridView1 ตื่อไปไม่เป็นครับ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 17:05:56 By : lamaka.tor
 

 

No. 4



โพสกระทู้ ( 345 )
บทความ ( 2 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : lamaka.tor เมื่อวันที่ 2016-10-07 17:05:56
รายละเอียดของการตอบ ::
ที่ผมจะให้ดูคือ SelectorClick , CellEnter

Code (VB.NET)
01.private void SelectorClick(object sender, EventArgs e)
02.    {
03.        switch (pCase) {
04.            case 1:
05.                //value from dataGridView1_CellEnter
06.                if (true) {
07.                    MessageBox.Show("Show Dialog here!!");
08.                    break; // TODO: might not be correct. Was : Exit Select
09.                }
10.                break;
11.        }
12.    }
13. 
14.private void DataGridView1_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
15.    {
16.        if (DataGridView1.Columns(e.ColumnIndex).Name == "Column1") {
17.            pCase = 1;
18.        }
19.    }


อันนีนะครับ คลิกแล้วจะให้ทำอะไรแล้วแล้วแต่เลยครับ


ซึ่งมันจะไปผูกกับ
Code (VB.NET)
01.private Button btnSelector = new Button();
02.    //สร้าง Buttnon
03.    private int pCase;
04.    //สำหรับ เก็บส่วนของการเลือก Column
05. 
06.    private void Form1_Load(System.Object sender, System.EventArgs e)
07.    {
08.        CreateButton(ref btnSelector);
09.        DataGridView1.Controls.Add(btnSelector);
10.    }
11. 
12.    private void DataGridView1_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
13.    {
14.        if (DataGridView1.Columns(e.ColumnIndex).Name == "Column1") {
15.            pCase = 1;
16.            Rectangle Loc = DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
17.            int Wid = DataGridView1.CurrentCell.Size.Width;
18.            btnSelector.Location = new Point(Loc.X - 25 + Wid, Loc.Y);
19.            btnSelector.Show();
20.        }
21.    }
22. 
23.    private void DataGridView1_CellLeave(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
24.    {
25.        if (btnSelector.Focused != true) {
26.            btnSelector.Hide();
27.        }
28. 
29.    }


กกก

คลิก Button ไปดึงอะไรมาก็แล้วแต่ ---> หลังจากดึงเสร็จจะให้ทำไรต่อก็แล้วแต่ครับ
ถ้าเป็นไปตามที่ผมพูดมา ก็ Code ชุดนี้เลยครับ


ประวัติการแก้ไข
2016-10-07 17:17:42
2016-10-07 17:22:00
2016-10-07 17:22:05
2016-10-07 17:22:36
2016-10-07 17:36:02
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 17:17:09 By : TheCom
 

 

No. 5



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 4 เขียนโดย : TheCom เมื่อวันที่ 2016-10-07 17:17:09
รายละเอียดของการตอบ ::
Code (C#)
01.private void doncument_listDetailDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
02.        {
03.            if (doncument_listDetailDataGridView[2, e.RowIndex].Value.ToString().Length > 0)
04.            {
05.                doncument_listDetailDataGridView[1, e.RowIndex].Value = docIDTextBox.Text;
06.            }
07.            if (e.ColumnIndex == 3)
08.                MessageBox.Show("3 doncument_listDetailDataGridView_CellEndEdit");
09.            
10.             
11.        }
12.private void doncument_listDetailDataGridView_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
13.        {
14.           // MessageBox.Show("" + e.ColumnIndex);
15.        }
16. 
17.        private void doncument_listDetailDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
18.        {
19.            if (e.ColumnIndex == 3)
20.                MessageBox.Show("3 5555");
21.        }
22. 
23.        private void doncument_listDetailDataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
24.        {
25.            if (e.ColumnIndex == 3)
26.                MessageBox.Show("3 doncument_listDetailDataGridView_CellEnter");
27.        }
28. 
29.        private void doncument_listDetailDataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
30.        {
31.            if (e.ColumnIndex == 3)
32.                MessageBox.Show("3 doncument_listDetailDataGridView_CellLeave");
33.        }


ไม่หือไม่อือ ไม่มีอะไรตอบมาเลยครับ

ปล. Button อยู่ฝั่ง DataGridViewcolumn ครับ
ผมก็อธิบายความต้องการไม่ถูกซะด้วยอ่าครับ
แต่ที่แน่ๆ คือพอผม เพิ่ม DataGridViewcolumn ใน DataGridView
แล้วใช้ Event ดังข้างต้น มันก็ไม่หืออือเลยครับ

ใจผมคิดว่าพอเรากด Button ฝั่ง DataGridViewcolumn ทำโน่นนี่นั่นเรียบร้อย
ก็ใช้ Event CellEndEdit จัดการโน่นนี่นั่นต่อแบบนี้ครับ

แต่ไง๋ไม่ไม่หืออือเลยครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 17:40:08 By : lamaka.tor
 

 

No. 6



โพสกระทู้ ( 345 )
บทความ ( 2 )



สถานะออฟไลน์


ใช้ตัวนี้ได้ไหมครับ ปกติผมใช้ตัวนี้เลย
Code (VB.NET)
01.private int pCase;
02.private void SelectorClick(object sender, EventArgs e)
03.    {
04.        switch (pCase) {
05.            case 1:
06.                //value from dataGridView1_CellEnter
07.                if (true) {
08.                    MessageBox.Show("Show Dialog here!!");
09.                    break; // TODO: might not be correct. Was : Exit Select
10.                }
11.                break;
12.        }
13.    }
14. 
15.private void DataGridView1_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
16.    {
17.        if (DataGridView1.Columns(e.ColumnIndex).Name == "Column1") {
18.            pCase = 1;
19.        }
20.    }



ประวัติการแก้ไข
2016-10-07 17:44:40
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 17:42:48 By : TheCom
 

 

No. 7



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 6 เขียนโดย : TheCom เมื่อวันที่ 2016-10-07 17:42:48
รายละเอียดของการตอบ ::
ของท่านผมลองแล้วได้ครับ

งั้นผมขอคิดดูก่อนว่าจะเปลี่ยนมาใช้แบบนี้ไม๊
พอดีกำลังหัดทำ Usercontrol ไปเรื่อย อ่าครับ
ถ้าเราทำเป็น Usercontrol เราก็ไม่ต้องมาเพิ่มโค้ดทุกครั้งเพื่อใช้งาน อ่าครับ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 17:57:00 By : lamaka.tor
 

 

No. 8

Guest


เล่นหูเล่นตากับอีเวนต์ (Events)

User Control
Code (VB.NET)
1.Public Class yourUserControl
2.    Protected Friend Event btnงามClick As EventHandler
3.    Private Sub btnหอย_Click(sender As Object, e As EventArgs) Handles btnหอย.Click
4.        RaiseEvent btnงามClick(sender, e) '*****
5.    End Sub
6.End Class


Forms XXX
Code (VB.NET)
1.Dim รักจิ่ม As New yourUserControl
2.Me.Controls.Add(รักจิ่ม)
3.AddHandler รักจิ่ม.btnงามClick, Sub(หอย, งาม)
4.                              MsgBox(DirectCast(หอย, Button).Name)
5.                          End Sub

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 21:45:54 By : หน้าฮี
 

 

No. 9

Guest


จาก #NO 6
Quote:
ใช้ตัวนี้ได้ไหมครับ ปกติผมใช้ตัวนี้เลย


ผมพูดตรงฯ มันเหมาะสำหรับ เด็กฯอนุบาล
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 21:49:47 By : หน้าฮี
 

 

No. 10

Guest


เล่าเรื่องจริงและตลกให้ฟังนะ
--- วันนี้ ผมเจอผู้หญิงอายุ 25 - 45 ปี หลายสิบคน
--- สิบในนั้นเรียกผมว่า คุณตา ผมนี่สะอึกเลย
--- สิบในนั้นเรียกผมว่า คุณลุง ผมนี่สะอึกเลย
--- สิบในนั้นเรียกผมว่า น้าฯ ผมนี่สะอึกเลย
...
...
...

สาววัยมันส์ คิดอะไรของมันหว่า?
...
...
...
กลับถึงบ้าน ผมแอบคิดอยู่ในใจ (เมียตู... ผ่านวัย 18 ปีมาได้ไม่กี่วัน เรียกตูว่า ผัวจ๋า ทุกคำ)

ปล. ...
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-07 22:20:47 By : หน้าฮี
 

 

No. 11



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

Code (C#)
01.public event EventHandler browseButtonClick;
02.        void browseButton_Click(object sender, EventArgs e)
03.        {
04.            DataGridViewDialogColumn filePathColumn = (DataGridViewDialogColumn)this.DataGridView.Columns[ColumnIndex];
05.            try
06.            {
07.                if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.OpenFileDialog)
08.                {
09.                    OpenFileDialog dialog = new OpenFileDialog();
10.                    if (dialog.ShowDialog() == DialogResult.OK)
11.                    {
12. 
13.                        base.Value = dialog.FileName.ToString();
14. 
15.                    }
16.                }
17.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.folderDialog)
18.                {
19.                    FolderBrowserDialog dialog = new FolderBrowserDialog();
20.                    if (dialog.ShowDialog() == DialogResult.OK)
21.                    {
22.                        base.Value = dialog.SelectedPath;
23.                    }
24.                }
25.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.colorDialog)
26.                {
27.                    ColorDialog dialog = new ColorDialog();
28.                    if (dialog.ShowDialog() == DialogResult.OK)
29.                    {
30.                        base.Value = dialog.Color.ToString() + ":"
31.                                       + dialog.Color.Name.ToString()
32.                                      + ": A=" + dialog.Color.A + " R=" + dialog.Color.R + " G=" + dialog.Color.G + " B=" + dialog.Color.B;
33.                    }
34.                }
35.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.fontDialog)
36.                {
37.                    FontDialog dialog = new FontDialog();
38.                    if (dialog.ShowDialog() == DialogResult.OK)
39.                    {
40.                        base.Value = dialog.Font.ToString();
41.                    }
42.                }
43.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.SaveFileDialog)
44.                {
45.                    SaveFileDialog dialog = new SaveFileDialog();
46.                    if (dialog.ShowDialog() == DialogResult.OK)
47.                    {
48.                        base.Value = dialog.FileName;
49.                    }
50.                }
51.            }
52.            catch (Exception)
53.            {
54.            }
55.            EventHandler _browseButtonClick = this.browseButtonClick;
56.        }


Err

ทำไมใช้ browseButtonClick ไม่ได้รึครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-13 14:22:17 By : lamaka.tor
 

 

No. 12



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ผมมาเริ่มศึกษา event ใหม่ครับ

Code (C#)
01.namespace UserControl_1
02.{
03.    public partial class UserControl2 : UserControl
04.    {
05.        public UserControl2()
06.        {
07.            InitializeComponent();
08.        }
09.        protected internal event EventHandler browseButtonClick;
10.        private void button1_Click(object sender, EventArgs e)
11.        {
12.            if (browseButtonClick != null)
13.            {
14.                browseButtonClick(this, e);
15.            }
16.        }
17.    }
18.}


Code (C#)
01.namespace UserControl_1
02.{
03.    public partial class Form1 : Form
04.    {
05.        public Form1()
06.        {
07.            InitializeComponent();
08.            
09. 
10.        }
11. 
12.        private void userControl21_browseButtonClick(object sender, EventArgs e)
13.        {
14.              MessageBox.Show("sfdsg");
15.        }
16.    }
17.}



เหมือนจะได้นะครับ แต่กับ datagrid ยังงงๆ อยู่เลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-13 16:16:04 By : lamaka.tor
 

 

No. 13



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

จาก No. 12

เท่าที่เดา(ล้วนๆ)
ผมว่า

browseButton_Click มันอยู่ใน DataGridViewDialogCell ซึ่งจะอยู่ใน DataGridViewDialogColumn แล้วก็อยู่ใน

DataGridView อีกที(usercontrol ใน usercontrol ซ้อน usercontrol ซ้อน usercontrol )

ต่างจาก No. 12 ที่ button1_Click อยู่ใน UserControl2 เลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-13 16:31:48 By : lamaka.tor
 

 

No. 14



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

Code (C#)
01.protected override void OnClick(DataGridViewCellEventArgs e)
02.        {
03.            base.OnClick(e);
04.        }
05. 
06.void browseButton_Click(object sender, EventArgs e)
07.        {
08.          // อยากใช้  base.OnClick(e); ได้มั่งครับ แต่ติด DataGridViewCellEventArgs ไม่รู้จะเอามาจากไหนครับ
09.        }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-15 11:10:33 By : lamaka.tor
 

 

No. 15



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอนนี้สามารถให้ ฟอร์ม เรียกใช้ Event ได้แล้วครับ

Code (C#)
001.using System;
002.using System.Collections.Generic;
003.using System.Drawing;
004.using System.Linq;
005.using System.Text;
006.using System.Windows.Forms;
007. 
008.namespace TORServices.Forms.Datagridview
009.{
010.    #region _DataGridViewDialog
011.    /// <summary>
012.    /// Hosts a collection of DataGridViewTextBoxCell cells.
013.    /// </summary>
014.    public class DataGridViewDialogColumn : System.Windows.Forms.DataGridViewColumn
015.    {
016.        private bool showBrowseButton;
017.        [System.ComponentModel.Browsable(true)]
018.        // [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
019.        [System.ComponentModel.DefaultValue(false)]
020.        [System.ComponentModel.Category("Appearance")]
021.        [System.ComponentModel.Description("Show a button in each cell for browsing for files.")]
022.        public enum SelectedPathType { colorDialog, folderDialog, fontDialog, OpenFileDialog, SaveFileDialog }
023.        public bool ShowBrowseButton
024.        {
025.            get { return showBrowseButton; }
026.            set
027.            {
028. 
029.                showBrowseButton = value;
030.            }
031.        }
032.  
033.        protected internal event EventHandler ButtonColumnClick;
034.        public virtual void browseColumnButton_Click(object sender, EventArgs e)
035.        {
036.            if(ButtonColumnClick != null)
037.                {
038.                    ButtonColumnClick(this, e);
039.                }
040.            
041.        }
042.         
043.        public override object Clone()
044.        {
045.            var clm = base.Clone() as DataGridViewDialogColumn;
046.            DataGridViewDialogColumn xxx = base.Clone() as DataGridViewDialogColumn;
047.            if (clm != null)
048.            {
049.                clm.SelectedMode = _selected;
050.                clm.ShowBrowseButton = showBrowseButton;
051.            }
052.            return clm;
053.            
054.        }
055.        private bool useOpenFileDialogOnButtonClick;
056.        [System.ComponentModel.Browsable(true)]
057.        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
058.        [System.ComponentModel.DefaultValue(false)]
059.        [System.ComponentModel.Category("Behavior")]
060.        [System.ComponentModel.Description("Dialog is dispalyed and on success the contents of the Cell is replaced with the new file path.")]
061.        public bool UseOpenFileDialogOnButtonClick
062.        {
063. 
064.            get { return useOpenFileDialogOnButtonClick; }
065.            set
066.            {
067.                useOpenFileDialogOnButtonClick = value;
068.            }
069.        }
070.        private SelectedPathType _selected;
071.        [System.ComponentModel.Browsable(true)]
072.        //[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
073.        // [System.ComponentModel.DefaultValue(SelectedPathType.OpenFileDialog)]
074.        [System.ComponentModel.Category("Behavior")]
075.        [System.ComponentModel.Description("Open Dialog is dispalyed and on success the contents of the Cell is replaced with the new  path.")]
076.        public SelectedPathType SelectedMode
077.        {
078.            get { return _selected; }
079.            set
080.            {
081.                _selected = value;
082.            }
083.        }
084.        public DataGridViewDialogColumn()
085.            : base(new DataGridViewDialogCell())
086.        {
087.          
088.        }
089. 
090.        public override System.Windows.Forms.DataGridViewCell CellTemplate
091.        {
092.            get
093.            {
094.                return base.CellTemplate;
095.            }
096.            set
097.            {
098.                if (null != value &&
099.                    !value.GetType().IsAssignableFrom(typeof(DataGridViewDialogCell)))
100.                {
101.                    throw new InvalidCastException("must be a DataGridViewDialogCell");
102.                }
103.                base.CellTemplate = value;
104.            }
105.        }
106.    }
107. 
108.    /// <summary>
109.    /// Displays editable text information in a DataGridView control. Uses
110.    /// PathEllipsis formatting if the column is smaller than the width of a
111.    /// displayed filesystem path.
112.    /// </summary>
113. 
114.    public class DataGridViewDialogCell : DataGridViewLinkCell
115.    {
116.      public  Button browseButton;
117. 
118.        Dictionary<Color, SolidBrush> brushes = new Dictionary<Color, SolidBrush>();
119. 
120.        protected virtual SolidBrush GetCachedBrush(Color color)
121.        {
122.            if (this.brushes.ContainsKey(color))
123.                return this.brushes[color];
124.            SolidBrush brush = new SolidBrush(color);
125.            this.brushes.Add(color, brush);
126.            return brush;
127.        }
128. 
129.        protected virtual bool RightToLeftInternal
130.        {
131.            get
132.            {
133.                return this.DataGridView.RightToLeft == RightToLeft.Yes;
134.            }
135.        }
136. 
137.        protected override void OnClick(DataGridViewCellEventArgs e)
138.        {
139.            base.OnClick(e);
140.            if (this.DataGridView.CurrentCell == this)
141.            {
142.                string _Value = Convert.ToString(base.Value);
143.                DataGridViewDialogColumn filePathColumn = (DataGridViewDialogColumn)this.DataGridView.Columns[ColumnIndex];
144.                if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.OpenFileDialog)
145.                {
146.                    if (!System.IO.File.Exists(_Value))
147.                    { MessageBox.Show("ไม่พบ " + _Value); }
148.                    else
149.                    { System.Diagnostics.Process.Start(_Value); }
150.                }
151.                if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.folderDialog)
152.                {
153.                    if (!System.IO.Directory.Exists(_Value))
154.                    { MessageBox.Show("ไม่พบ " + _Value); }
155.                    else
156.                    { System.Diagnostics.Process.Start(_Value); }
157.                }
158.            }
159.        }
160.        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
161.        {
162.            if (cellStyle == null) { throw new ArgumentNullException("cellStyle"); }
163.            this.PaintPrivate(graphics, clipBounds, cellBounds, rowIndex, cellState, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
164.        }
165. 
166.        protected Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
167.        {
168.            System.Diagnostics.Debug.WriteLine(string.Format("Painting Cell row {0} for rowindex {2} with rectangle {1}", this.RowIndex, cellBounds, rowIndex));
169.            SolidBrush cachedBrush;
170.            Rectangle empty = Rectangle.Empty;
171.            if (((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None)) { this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); }
172.            Rectangle rectangle2 = this.BorderWidths(advancedBorderStyle);
173.            Rectangle borderedCellRectangle = cellBounds;
174.            borderedCellRectangle.Offset(rectangle2.X, rectangle2.Y);
175.            borderedCellRectangle.Width -= rectangle2.Right;
176.            borderedCellRectangle.Height -= rectangle2.Bottom;
177.            Point currentCellAddress = base.DataGridView.CurrentCellAddress;
178.            bool isFirstCell = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex);
179.            bool flagisFirstCellAndNotEditing = isFirstCell && (base.DataGridView.EditingControl != null);
180.            bool thisCellIsSelected = (cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;
181.            cachedBrush = ((((paintParts & DataGridViewPaintParts.SelectionBackground) != DataGridViewPaintParts.None) && thisCellIsSelected) && !flagisFirstCellAndNotEditing) ? GetCachedBrush(cellStyle.SelectionBackColor) : GetCachedBrush(cellStyle.BackColor);
182. 
183.            if (((((paintParts & DataGridViewPaintParts.Background) != DataGridViewPaintParts.None)) && ((cachedBrush.Color.A == 0xff) && (borderedCellRectangle.Width > 0))) && (borderedCellRectangle.Height > 0))
184.            {
185.                graphics.FillRectangle(cachedBrush, borderedCellRectangle);
186.            }
187.            if (cellStyle.Padding != Padding.Empty)
188.            {
189.                if (RightToLeftInternal)
190.                {
191.                    borderedCellRectangle.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
192.                }
193.                else
194.                {
195.                    borderedCellRectangle.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
196.                }
197.                borderedCellRectangle.Width -= cellStyle.Padding.Horizontal;
198.                borderedCellRectangle.Height -= cellStyle.Padding.Vertical;
199.            }
200.            if (((isFirstCell) && (!flagisFirstCellAndNotEditing && ((paintParts & DataGridViewPaintParts.Focus) != DataGridViewPaintParts.None))) && ((ShowFocusCues && base.DataGridView.Focused) && ((borderedCellRectangle.Width > 0) && (borderedCellRectangle.Height > 0))))
201.            {
202.                ControlPaint.DrawFocusRectangle(graphics, borderedCellRectangle, Color.Empty, cachedBrush.Color);
203.            }
204.            Rectangle cellValueBounds = borderedCellRectangle;
205.            string text = formattedValue as string;
206.            if ((text != null) && (!flagisFirstCellAndNotEditing))
207.            {
208.                int y = (cellStyle.WrapMode == DataGridViewTriState.True) ? 1 : 2;
209.                borderedCellRectangle.Offset(0, y);
210.                borderedCellRectangle.Width = borderedCellRectangle.Width;
211.                borderedCellRectangle.Height -= y + 1;
212.                if ((borderedCellRectangle.Width > 0) && (borderedCellRectangle.Height > 0))
213.                {
214.                    TextFormatFlags flags = TextFormatFlags.PathEllipsis;
215. 
216.                    if (((paintParts & DataGridViewPaintParts.ContentForeground) != DataGridViewPaintParts.None))
217.                    {
218.                        if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.GlyphOverhangPadding) { flags |= TextFormatFlags.EndEllipsis; }
219.                        DataGridViewDialogColumn filePathColumn = (DataGridViewDialogColumn)this.DataGridView.Columns[ColumnIndex];
220. 
221.                        if (this.RowIndex >= 0)
222.                        {
223. 
224.                            bool changed = false;
225.                            if ((browseButton.Width != System.Math.Max(10, borderedCellRectangle.Width / 4)) && (browseButton.Width != 20))
226.                            {
227.                                System.Diagnostics.Trace.WriteLine(string.Format("browseButton Width was incorrect:{0} for given rectangle:{1}", browseButton.Width, borderedCellRectangle));
228.                                browseButton.Width = System.Math.Max(10, borderedCellRectangle.Width / 4);
229.                                browseButton.Width = System.Math.Min(browseButton.Width, 20);
230.                                changed = true;
231.                            }
232.                            if (browseButton.Height != (borderedCellRectangle.Height + 4))
233.                            {
234.                                System.Diagnostics.Trace.WriteLine(string.Format("browseButton Height was incorrect:{0} for given rectangle:{1}", browseButton.Height, borderedCellRectangle));
235.                                browseButton.Height = borderedCellRectangle.Height + 4;
236.                                changed = true;
237.                            }
238.                            Point loc = new Point();
239.                            loc.X = borderedCellRectangle.X + borderedCellRectangle.Width - browseButton.Width;
240.                            loc.Y = borderedCellRectangle.Y - 4;
241.                            if (browseButton.Location != loc)
242.                            {
243.                                System.Diagnostics.Trace.WriteLine(string.Format("browseButton location was incorrect:{0} for given rectangle:{1} with loc: {2}", browseButton.Location, borderedCellRectangle, loc));
244.                                browseButton.Location = loc;
245.                                changed = true;
246.                            }
247.                            if (changed)
248.                                browseButton.Invalidate();
249.                            if (!this.DataGridView.Controls.Contains(browseButton))
250.                                this.DataGridView.Controls.Add(browseButton);
251.                            borderedCellRectangle.Width -= browseButton.Width;
252.                        }
253.                    }
254.                    TextRenderer.DrawText(graphics, text, cellStyle.Font, borderedCellRectangle, thisCellIsSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor, flags);
255. 
256. 
257.                }
258.            }
259.            if ((base.DataGridView.ShowCellErrors) && ((paintParts & DataGridViewPaintParts.ErrorIcon) != DataGridViewPaintParts.None))
260.            {
261.                if ((!string.IsNullOrEmpty(errorText) && (cellValueBounds.Width >= 20)) && (cellValueBounds.Height >= 0x13))
262.                {
263.                    Rectangle iconBounds = this.GetErrorIconBounds(graphics, cellStyle, rowIndex);
264.                    if ((iconBounds.Width >= 4) && (iconBounds.Height >= 11))
265.                    {
266.                        iconBounds.X += cellBounds.X;
267.                        iconBounds.Y += cellBounds.Y;
268.                        Bitmap errorBitmap = new Bitmap(typeof(DataGridViewCell), "DataGridViewRow.error.bmp");
269.                        errorBitmap.MakeTransparent();
270.                        if (errorBitmap != null)
271.                        {
272.                            lock (errorBitmap)
273.                            {
274.                                graphics.DrawImage(errorBitmap, iconBounds, 0, 0, 12, 11, GraphicsUnit.Pixel);
275.                            }
276.                        }
277.                    }
278.                }
279. 
280.            }
281.            return empty;
282.        }
283. 
284.        public bool ShowFocusCues
285.        {
286.            get { return true; }
287.        }
288. 
289.        protected bool ApplyVisualStylesToHeaders
290.        {
291.            get
292.            {
293.                if (Application.RenderWithVisualStyles)
294.                {
295.                    return this.DataGridView.EnableHeadersVisualStyles;
296.                }
297.                return false;
298.            }
299.        }
300.      /*  private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
301.        {
302.            if (base.Value.ToString().Length > 0)
303.            {
304.                System.Diagnostics.Process.Start(base.Value.ToString());
305.            }
306. 
307.        }*/
308. 
309.     // protected internal event EventHandler ButtonCellClick;
310.      void browseButton_Click(object sender, EventArgs e)
311.        {
312.            DataGridViewDialogColumn filePathColumn = (DataGridViewDialogColumn)this.DataGridView.Columns[ColumnIndex];
313.            try
314.            {
315.                if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.OpenFileDialog)
316.                {
317.                    OpenFileDialog dialog = new OpenFileDialog();
318.                    if (dialog.ShowDialog() == DialogResult.OK)
319.                    {
320. 
321.                        base.Value = dialog.FileName.ToString();
322. 
323.                    }
324.                }
325.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.folderDialog)
326.                {
327.                    FolderBrowserDialog dialog = new FolderBrowserDialog();
328.                    if (dialog.ShowDialog() == DialogResult.OK)
329.                    {
330.                        base.Value = dialog.SelectedPath;
331.                    }
332.                }
333.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.colorDialog)
334.                {
335.                    ColorDialog dialog = new ColorDialog();
336.                    if (dialog.ShowDialog() == DialogResult.OK)
337.                    {
338.                        base.Value = dialog.Color.ToString() + ":"
339.                                       + dialog.Color.Name.ToString()
340.                                      + ": A=" + dialog.Color.A + " R=" + dialog.Color.R + " G=" + dialog.Color.G + " B=" + dialog.Color.B;
341.                    }
342.                }
343.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.fontDialog)
344.                {
345.                    FontDialog dialog = new FontDialog();
346.                    if (dialog.ShowDialog() == DialogResult.OK)
347.                    {
348.                        base.Value = dialog.Font.ToString();
349.                    }
350.                }
351.                else if (filePathColumn.SelectedMode == DataGridViewDialogColumn.SelectedPathType.SaveFileDialog)
352.                {
353.                    SaveFileDialog dialog = new SaveFileDialog();
354.                    if (dialog.ShowDialog() == DialogResult.OK)
355.                    {
356.                        base.Value = dialog.FileName;
357.                    }
358.                }
359.            }
360.            catch (Exception)
361.            {
362.            }
363.            filePathColumn.browseColumnButton_Click(this, e);
364. 
365.          /*  if (ButtonCellClick != null)
366.            {
367.                ButtonCellClick(this, e);
368.            }*/
369.             
370.        }
371.        public DataGridViewDialogCell()
372.            : base()
373.        {
374.            browseButton = new Button();
375.            browseButton.Text = "…";
376.            browseButton.Click += new EventHandler(browseButton_Click);
377.        }
378.    }
379.    #endregion
380.}


Code (C#)
01.private void Form1_Load(object sender, EventArgs e)
02.        {
03.           userControl21.browseButtonClick+=new EventHandler(this.userControl21_browseButtonClick);
04.           Column1.ButtonColumnClick += new EventHandler(this.button1_Click);
05.        }
06. 
07.        private void button1_Click(object sender, EventArgs e)
08.        {
09.            MessageBox.Show("55555");
10.        }


แต่ที่ไม่ชอบใจคือ ต้องเรียกใช้จาก Column1 อยากทราบว่าเราจะให้เรียกใช้ผ่าน dataGridView1 ยังไงครับ

และอีกอย่างครับ
ผมต้องการให้โชว์ event ใน event ของ dataGridView1 ต้องทำยังไงครับ

555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-17 00:26:51 By : lamaka.tor
 

 

No. 16



โพสกระทู้ ( 821 )
บทความ ( 0 )



สถานะออฟไลน์


ถ้าเข้าใจไม่ผิด
จะทำปุ่ม Browse เล็ก ๆ ใน Textbox เพื่อกดเลือกไฟล์ใช่ไหมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-17 08:16:57 By : fonfire
 

 

No. 17



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

Browse เล็ก ๆ ใน Datagrid ครับ

แต่มันต้องทำใน Column และ cell ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-17 08:58:00 By : lamaka.tor
 

 

No. 18



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ผมลองสร้าง event ใน textbox ก็ไม่ขึ้นมาเหมือนกันครับ
Code (C#)
001.using System;
002.using System.Collections.Generic;
003.using System.Drawing;
004.using System.Linq;
005.using System.Text;
006.using System.Windows.Forms;
007.namespace TORServices.Forms
008.{
009.    class TextboxDialog:TextBox
010.    {
011.        Button browseButton;
012.        public enum SelectedPathType { colorDialog, folderDialog, fontDialog, OpenFileDialog, SaveFileDialog }
013.        private SelectedPathType _selected;
014.        [System.ComponentModel.Browsable(true)]
015.        [System.ComponentModel.Category("Behavior")]
016.        [System.ComponentModel.Description("Open Dialog is dispalyed and on success the contents of the Cell is replaced with the new  path.")]
017.        public SelectedPathType SelectedMode
018.        {
019.            get { return _selected; }
020.            set
021.            {
022.                _selected = value;
023.            }
024.        }
025.     
026. 
027.        protected override void OnDoubleClick(EventArgs e)
028.         {
029.           base.OnDoubleClick(e);
030.            if (_selected == SelectedPathType.OpenFileDialog)
031.            {
032.                if (!System.IO.File.Exists(this.Text))
033.                { MessageBox.Show("ไม่พบ " + this.Text); }
034.                else
035.                { System.Diagnostics.Process.Start(this.Text); }
036.            }
037.            if (_selected == SelectedPathType.folderDialog)
038.            {
039.                if (!System.IO.Directory.Exists(this.Text))
040.                { MessageBox.Show("ไม่พบ " + this.Text); }
041.                else
042.                { System.Diagnostics.Process.Start(this.Text); }
043.            }
044.        }
045.        protected override void OnResize(EventArgs e)
046.        {
047.            base.OnResize(e);
048.            browseButton.Size = new Size(28, this.ClientSize.Height + 2);
049.            browseButton.Location = new Point(this.ClientSize.Width - browseButton.Width, -1);
050.        }
051.        protected internal event EventHandler ButtonCellClick;
052. 
053.        void browseButton_Click(object sender, EventArgs e)
054.        {
055.            if (_selected == SelectedPathType.OpenFileDialog)
056.                {
057.                    using (OpenFileDialog dialog = new OpenFileDialog())
058.                    {
059.                        if (dialog.ShowDialog() == DialogResult.OK)
060.                            base.Text = dialog.FileName.ToString();
061.                    }
062.                }
063.            else if (_selected == SelectedPathType.folderDialog)
064.                {
065.                   using ( FolderBrowserDialog dialog = new FolderBrowserDialog())
066.                   { if (dialog.ShowDialog() == DialogResult.OK)
067.                        base.Text = dialog.SelectedPath;
068.                    }
069.                }
070.            else if (_selected == SelectedPathType.colorDialog)
071.                {
072.                   using(ColorDialog dialog = new ColorDialog())
073.                    { if (dialog.ShowDialog() == DialogResult.OK)
074.                    
075.                        base.Text = dialog.Color.ToString() + ":"
076.                                       + dialog.Color.Name.ToString()
077.                                      + ": A=" + dialog.Color.A + " R=" + dialog.Color.R + " G=" + dialog.Color.G + " B=" + dialog.Color.B;
078.                    }
079.                }
080.            else if (_selected == SelectedPathType.fontDialog)
081.                {
082.                  using( FontDialog dialog = new FontDialog())
083.                    { if (dialog.ShowDialog() == DialogResult.OK)
084.                        base.Text = dialog.Font.ToString();
085.                    }
086.                }
087.            else if (_selected == SelectedPathType.OpenFileDialog)
088.                {
089.                   using( SaveFileDialog dialog = new SaveFileDialog())
090.                    { if (dialog.ShowDialog() == DialogResult.OK)
091.                        base.Text = dialog.FileName;
092.                    }
093.                }
094.                ButtonCellClick(sender, e);
095.        }
096. 
097. 
098.         public TextboxDialog()
099.         {
100.             browseButton = new Button();
101.             browseButton.Text = "...";
102.             browseButton.SizeChanged += (o, e) => { OnResize(e); };
103.             browseButton.Click += new EventHandler(this.browseButton_Click);
104.             browseButton.Size = new Size(28, this.ClientSize.Height + 2);
105.             browseButton.Location = new Point(this.ClientSize.Width - browseButton.Width, -1);
106.                 this.Controls.Add(browseButton);
107. 
108.         }
109.    }
110.}




Code (C#)
01.public partial class Form1 : Form
02.    {
03.        public Form1()
04.        {
05.            InitializeComponent();
06.        }
07. 
08.        private void Form1_Load(object sender, EventArgs e)
09.        {
10.            textboxDialog1.ButtonCellClick += new EventHandler(this.ButtonCellClick);
11.        }
12. 
13.        private void ButtonCellClick(object sender, EventArgs e)
14.        {
15.           MessageBox.Show("Test 5555");
16.        }
17. 
18.        
19.    }


ต้องไปเพิ่มใน โค๊ด เหมือนกัน รบกวนท่านผู้รู้มั่งครับ
ทำยังไง Event ถึงใช้งานในหน้า design ได้เหมือน Event อื่นๆครับ

_/\_
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-18 11:32:58 By : lamaka.tor
 

 

No. 19



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

อยากให้ เลาเลือก OpenFileDialog, SaveFileDialog

ให้เพิ่มอีก property ขึ้นมาคือ path folder ครับ
ผมอยากผูก column ไว้เลย
เวลาคลิกที่ปุ่มจะให้เอาไฟล์ไปเก็บใน path folder นั้นๆ ได้เลย
ใน datagrid ก็จะโชว์แค่ ชื่อไฟล์
เวลาคลิกที่ cell ก็จะรวม path folder+ "\\" ชื่อไฟล์ ประมาณนี้ครับ

ถ้าเลือกตัวอื่นๆเช่น colorDialog, fontDialog property path folder ก็จะหายไป แบบนี้อ่าครับ
ต้องทำยังไงรึ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-20 11:31:01 By : lamaka.tor
 

 

No. 20

Guest


Quote:
ต้องไปเพิ่มใน โค๊ด เหมือนกัน รบกวนท่านผู้รู้มั่งครับ


ผมถามคุณตรงฯ คุณคิดว่าผมรู้หรือไม่?

ปล. บางสิ่งบางอย่าง มันคุยกันในที่่สาธารณะไมได้ ( ขุดิดนได้โดยใช้ จอบกับเสียม ในบางโอกาสเรา(คนที่รู้)มักใช้งาน ต่างกัน)

+55555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-27 20:48:41 By : หน้าฮี
 

 

No. 21



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-28 09:03:23 By : lamaka.tor
 

 

No. 22

Guest


@lamaka.tor
คุณเข้า www.codeproject.com และค้นหาคำว่า
Quote:
Culture Aware Month Calendar and DatePicker



จริงฯแล้วผมอยากได้
DateTimePicker และ DataGridView DateTimePicker Column ที่รันบน Windows Applications
(ระยะหลังฯ ผมไม่ค่อยได้เขียนสักเท่าไหร่? จะเรียกว่า ผมถนัดและเชี่ยวชาญในการเขียน Website เสียมากกว่า)

ปล. ขอให้โชคดีครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-28 14:40:47 By : หน้าฮี
 

 

No. 23

Guest


จาก #NO 22 ปัจจุบันนี้หายากมากฯ ที่ตนฯหนึ่งจะเป็น
--- โปรแกรมเมอร์จริงฯ และเป็น SA ในคนฯเดียวกัน (รอบรู้ทุกอย่าง)


ส่วนใหญ่ก็ของปลอมทั้งนั้น อาศัยคำว่า "ทำงานเป็นทีม" เพื่อหากิน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-28 14:45:19 By : หน้าฮี
 

 

No. 24

Guest


ผมมาบ่นเล่าให้ฟัง

ผมจุดธูป ไหว้ และขอพรสิ่งศักดิ์สิทธิ์ (แอบขอและแอบคิดอยู่ในใจกับเทวดา)
อันนี้ผมกำลังพูดถึง Windows Applications และผมจะเอาไปใช้กับ DataGridView

กรองข้อมูลใน DataGridView โดยใช้ Column ComboBox
(Cascading Comboboxes in DataGridView Windows Application)

ตอนนี้ผมต้องการแค่ ประเทศ ---> จังหวัด --> อำเภอ


Code (VB.NET)
01.Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
02.    Dim ประเทศ As New Country() With {.CountryCode = "TH",
03.                                     .CountryName = "ประเทศไทย",
04.                                     .Provinces = New List(Of Province)() From {New Province() With {.ProvinceCode = "01",
05.                                                                                                     .ProvinceName = "กรุงเทพฯ",
06.                                                                                                     .Amphoes = New List(Of Amphoe)() From {New Amphoe() With {.AmphoeCode = "11",
07.                                                                                                                                                               .AmphoeName = "เขตพระโขนง"
08.                                                                                                                                                              },
09.                                                                                                                                            New Amphoe() With {.AmphoeCode = "77",
10.                                                                                                                                                               .AmphoeName = "เขตบางหำ"
11.                                                                                                                                                              }
12.                                                                                                                                           }
13.                                                                                                    }
14.                                                                               }
15.                                     }
16. 
17.End Sub



Code (VB.NET)
01.'Model ประเทส
02.Public Class Country
03.    Public Property CountryCode As String = "TH"
04.    Public Property CountryName As String = "ประเทศไทย"
05.    Public Property Provinces As List(Of Province) = Nothing
06.End Class
07. 
08.'Model จังหวัด
09.<strong>Code (VB.NET)</strong>
10.[vb]Public Class Province
11.    Public Property ProvinceCode As String = String.Empty
12.    Public Property ProvinceName As String = String.Empty
13.    Public Property Amphoes As List(Of Amphoe) = Nothing
14.End Class

'Model อำเภอ
Code (VB.NET)
1.Public Class Amphoe
2.    Public Property AmphoeCode As String = String.Empty
3.    Public Property AmphoeName As String = String.Empty
4.End Class

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-29 22:34:37 By : หน้าฮี
 

 

No. 25

Guest


จาก #NO 24 จริงฯแล้วผมเขียน C#.NET ได้คล่องแคล่วกว่า VB.NET
(ผมดักเด็กฯ ผู้เชี่ยวชาญ C# [พวกละเมอในภาษา]) +55555

ผมมักเลือกใช้ VB.NET ในงานหลักฯของผมเสมอ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-29 22:49:07 By : หน้าฮี
 

 

No. 26

Guest


@lamaka.tor

และคนอื่นฯ พวกคุณคิดว่าผมรู้จักคำว่า MVC หรือไม่ล่ะ?
+55555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-29 22:55:10 By : หน้าฮี
 

 

No. 27



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ช่วงนี้รันเครื่องครับ

น้ำใต้ดิน 300 เครื่องสำอางค์ 60
งอมจนไม่มีตรวจโค้ด DatePicker ที่ให้มาเลยครับ
เด๋วอาทิตย์หน้าก็โดน Audit อีก กรรม แบบบ้านๆ ครับ

ว่าแต่ ยากเอาการนะครับ 55555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-30 10:52:19 By : lamaka.tor
 

 

No. 28

Guest


@ ALL

The life must be learning all time and not finish.
We never know that what will we met when we will have learning.
Even though, we perhaps meet good and bad person in the same time.
Maybe this situation will be awaked us for continued learning by never ending.


ปล.
someone love one.
someone love two.
but I love one.
that one is ...
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-10-31 14:41:27 By : หน้าฮี
 

 

No. 29

Guest


@lamaka.tor, QC_C0M

ผมเห็นว่าพวกคุณมีความถนัด DataGridView (Windows Application)
--- สมมุติว่าอยู่ในห้วงความต้องการ ลึกสุดฯ "เอาอยู่หรือไม่?"
--- จากรูปภาพด้านล่าง (ถ้าพอมีเวลาว่าง (ไม่ว่างก็ไม่เป็นไร) ลองเดาความต้องการของผมเล่นฯดู)


จากรูปภาพด้านล่าง มีสิทธิ์ไม่เกิน 3 ระเบียน แล้ววิธีการคิดมันต้องอธิบายออกมาอย่างไร?
--- อันนี้บนเงื่อนไขที่ไม่ซับซ้อน (ของจริงโหดร้ายยิ่งกว่านี้)
dgv_deep_001

งานโปรแกรมมิ่ง ผมพูดได้ว่า "เด็กฯ"
--- บางคนเขียนโปรแกรมเก่งแต่เขียนเอกสารไม่เป็น (ไม่เป็นเลย) อันนี้แย่มากฯ
--- บางคนเขียนโปรแกรมไม่เก่งแต่เขียนเอกสารเป็น (พอใช้ได้) อันนี้พอใช้ได้
--- บางคนก็กินบุญเก่า (อันนี้แย่มากฯฯฯฯ)


ปล. จากรูปภาพด้านบน จริงฯแล้วผมยังมีคำถามกับตัวเองอีกมากมาย? (ผมไม่เคยง้อใครเหมือนกัน)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-03 15:55:03 By : หน้าฮี
 

 

No. 30

Guest


จาก #NO 29 อันนี้เป็น Source Code ที่กรองจำนวนผู้มีสิทธิ์
(ในเบื้องต้น เพื่อประกอบความเข้าใจ)

Code (VB.NET)
1.Private Function CalculateRight() As Short
2.    Dim row = From r As DataGridViewRow In DataGridView1.Rows
3.              Where (Not r.IsNewRow And r.Cells(3).Value IsNot DBNull.Value) AndAlso r.Cells(3).Value = 1S
4. 
5.    Return If(row Is Nothing, 0, row.Count)
6.End Function



ปล. จะเรียก Function นี้ที่ไหนก็ตามสะดวก? (Events ใน Windows Application DataGridView มันพันกันอิรุงตุงนัง)
(ถ้าเป็นบนเวป หลับตาทำก็ยังได้เลย)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-03 16:05:14 By : หน้าฮี
 

 

No. 31

Guest


จาก #NO 29 - 30 เดี๋ยวจะหาว่า เขียนเวปไซต์ไม่เป็น +55555

อันนี้เล่นบน Tag HTML <table></table>
ถ้าจำไม่ผิดคือระบบ IC และไม่มี ViewState ปะปนด้วย

Code (VB.NET)
01.Private Function listCopy() As List(Of WL_Model.ICD)
02.    Return (From r In rtABC.Items.Cast(Of RepeaterItem)() Select New WL_Model.ICD() With {.Part_NO = DirectCast(r.FindControl("txtPart_NO"), WL_Controls.WL_TextBox).Text,
03.                                                                                          .xTitleTH = DirectCast(r.FindControl("lblPart_Desc"), WL_Controls.WL_TextBox).Text,
04.                                                                                          .Tran_Qty = DirectCast(r.FindControl("txtTran_Qty"), WL_Controls.WL_TextBox).Text,
05.                                                                                          .UM = DirectCast(r.FindControl("cboUM"), HtmlSelect).Value,
06.                                                                                          .From_Bal = DirectCast(r.FindControl("cboBalType"), HtmlSelect).Value,
07.                                                                                          .Tran_Amt = DirectCast(r.FindControl("txtTran_Amt"), WL_Controls.WL_TextBox).Text,
08.                                                                                          .xID = CInt(DirectCast(r.FindControl("cbRemoveAttachment"), CheckBox).Checked)
09.                                                                                         }).ToList()
10.End Function

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-03 16:26:03 By : หน้าฮี
 

 

No. 32

Guest


จาก #NO 29 -31 อันนี้ผมพูดติดตลก
--- ให้โปรแกรมเมอร์เด็กฯ 10 - 20 หรือ 100 คน เขียน ให้เวลาไปเลย 10 ปี
--- เขียนเสร็จหรือเปล่า? +55555


ปล. เก่งอยู่อย่างเดียวนั่นคือ "คำว่าขี้เกียจ"
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-03 16:33:04 By : หน้าฮี
 

 

No. 33



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

พักซักหน่อยก่อนครับ

ช่วงนี้หัดเขียน Autocad ต่อ
หัดทำนาฬิกาไม้ครับ
https://www.youtube.com/watch?v=tAKCV5RBnFQ

จนถึงทุกวันนี้ยังไม่เข้าใจว่าตกลง ผมเป็นนักวิทย์ จริงๆ หรือ เขาจ้างมาให้เป็นช่างก็ไม่รู้
ซ่อมดะไปเรื่อย 5555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-04 11:13:42 By : lamaka.tor
 

 

No. 34



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ต้องเร่งทำ Uncer,Calibration,Validate กะ PT ให้เสร็จก่อน 20
เลยไม่ค่อยมีเวลาเขียนโปรแกรมต่อซักที

เย็นๆหน่อยก็เหล้าขาวอีก ไม่ว๊างไม่ว่าง ตามประสาคนบ้านๆ ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-11-04 11:20:17 By : lamaka.tor
 

 

No. 35



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์


GUI แบบข้างบนสุดของโพสต์นี้คุณทำอย่างไรอ่ะครับ
20190513-1
ผมอยากทำคล้ายๆ แบบคุณ อยากขอไอเดียหน่อยครับ


ประวัติการแก้ไข
2019-05-13 11:35:05
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-05-13 11:30:47 By : jaypang
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# WinApp สอบถามเรื่อง การสร้าง Usercontrol อยากทราบ Event ของ DataGridView ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่