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,028

HOME > .NET Framework > Forum > สอบถามการสร้าง Button และ Textbox ใน DataGridview หน่อยครับ



 

สอบถามการสร้าง Button และ Textbox ใน DataGridview หน่อยครับ

 



Topic : 119572



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



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




สอบถามการสร้าง Button ใน DataGridview หน่อยครับ
คืออยากรวมระหว่าง textbox กับ Button ให้อยู่ในช่องเดียวกัน ต้องทำยังไงครับ

ss



Tag : .NET, Ms SQL Server 2005, VB.NET









ประวัติการแก้ไข
2015-10-26 17:17:33
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-10-26 17:17:04 By : TheCom View : 1497 Reply : 7
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

กำหนดแบบ Custom Column ครับ มันมีแบบ Button มาให้ครับ



DataGridView (Win Form) สร้าง Custom แบบ Column/Header และการ Loop เพื่อ Summary ผลรวม (VB.Net,C#)







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-26 17:35:52 By : mr.win
 


 

No. 2



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



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

ของผมใช้โค้ดบ้านๆแบบนี้ครับ
แต่ใช้สำหรับ select FilePath ลองเอาไปปรับแก้เอาครับ
Code (C#)
public class DataGridViewFilePathCell : DataGridViewTextBoxCell
    {
        Button browseButton;

        Dictionary<Color, SolidBrush> brushes = new Dictionary<Color, SolidBrush>();
        protected virtual SolidBrush GetCachedBrush(Color color)
        {
            if (this.brushes.ContainsKey(color))
                return this.brushes[color];
            SolidBrush brush = new SolidBrush(color);
            this.brushes.Add(color, brush);
            return brush;
        }

        protected virtual bool RightToLeftInternal
        {
            get
            {
                return this.DataGridView.RightToLeft == RightToLeft.Yes;
            }
        }
        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)
        {
            if (cellStyle == null) { throw new ArgumentNullException("cellStyle"); }
            this.PaintPrivate(graphics, clipBounds, cellBounds, rowIndex, cellState, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
        }

        protected Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            System.Diagnostics.Debug.WriteLine(string.Format("Painting Cell row {0} for rowindex {2} with rectangle {1}", this.RowIndex, cellBounds, rowIndex));
            SolidBrush cachedBrush;
            Rectangle empty = Rectangle.Empty;
            if (((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None)) { this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); }
            Rectangle rectangle2 = this.BorderWidths(advancedBorderStyle);
            Rectangle borderedCellRectangle = cellBounds;
            borderedCellRectangle.Offset(rectangle2.X, rectangle2.Y);
            borderedCellRectangle.Width -= rectangle2.Right;
            borderedCellRectangle.Height -= rectangle2.Bottom;
            Point currentCellAddress = base.DataGridView.CurrentCellAddress;
            bool isFirstCell = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex);
            bool flagisFirstCellAndNotEditing = isFirstCell && (base.DataGridView.EditingControl != null);
            bool thisCellIsSelected = (cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;
            cachedBrush = ((((paintParts & DataGridViewPaintParts.SelectionBackground) != DataGridViewPaintParts.None) && thisCellIsSelected) && !flagisFirstCellAndNotEditing) ? GetCachedBrush(cellStyle.SelectionBackColor) : GetCachedBrush(cellStyle.BackColor);

            if (((((paintParts & DataGridViewPaintParts.Background) != DataGridViewPaintParts.None)) && ((cachedBrush.Color.A == 0xff) && (borderedCellRectangle.Width > 0))) && (borderedCellRectangle.Height > 0))
            {
                graphics.FillRectangle(cachedBrush, borderedCellRectangle);
            }
            if (cellStyle.Padding != Padding.Empty)
            {
                if (RightToLeftInternal)
                {
                    borderedCellRectangle.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    borderedCellRectangle.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                borderedCellRectangle.Width -= cellStyle.Padding.Horizontal;
                borderedCellRectangle.Height -= cellStyle.Padding.Vertical;
            }
            if (((isFirstCell) && (!flagisFirstCellAndNotEditing && ((paintParts & DataGridViewPaintParts.Focus) != DataGridViewPaintParts.None))) && ((ShowFocusCues && base.DataGridView.Focused) && ((borderedCellRectangle.Width > 0) && (borderedCellRectangle.Height > 0))))
            {
                ControlPaint.DrawFocusRectangle(graphics, borderedCellRectangle, Color.Empty, cachedBrush.Color);
            }
            Rectangle cellValueBounds = borderedCellRectangle;
            string text = formattedValue as string;
            if ((text != null) && (!flagisFirstCellAndNotEditing))
            {
                int y = (cellStyle.WrapMode == DataGridViewTriState.True) ? 1 : 2;
                borderedCellRectangle.Offset(0, y);
                borderedCellRectangle.Width = borderedCellRectangle.Width;
                borderedCellRectangle.Height -= y + 1;
                if ((borderedCellRectangle.Width > 0) && (borderedCellRectangle.Height > 0))
                {
                    TextFormatFlags flags = //DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                        TextFormatFlags.PathEllipsis;

                    if (((paintParts & DataGridViewPaintParts.ContentForeground) != DataGridViewPaintParts.None))
                    {
                        if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.GlyphOverhangPadding) { flags |= TextFormatFlags.EndEllipsis; }
                        DataGridViewFilePathColumn filePathColumn = (DataGridViewFilePathColumn)this.DataGridView.Columns[ColumnIndex];

                        if (this.RowIndex >= 0)
                        {

                            bool changed = false;
                            if ((browseButton.Width != Math.Max(10, borderedCellRectangle.Width / 4)) && (browseButton.Width != 20))
                            {
                                System.Diagnostics.Trace.WriteLine(string.Format("browseButton Width was incorrect:{0} for given rectangle:{1}", browseButton.Width, borderedCellRectangle));
                                browseButton.Width = Math.Max(10, borderedCellRectangle.Width / 4);
                                browseButton.Width = Math.Min(browseButton.Width, 20);
                                changed = true;
                            }
                            if (browseButton.Height != (borderedCellRectangle.Height + 4))
                            {
                                System.Diagnostics.Trace.WriteLine(string.Format("browseButton Height was incorrect:{0} for given rectangle:{1}", browseButton.Height, borderedCellRectangle));
                                browseButton.Height = borderedCellRectangle.Height + 4;
                                changed = true;
                            }
                            Point loc = new Point();
                            loc.X = borderedCellRectangle.X + borderedCellRectangle.Width - browseButton.Width;
                            loc.Y = borderedCellRectangle.Y - 4;
                            if (browseButton.Location != loc)
                            {
                                System.Diagnostics.Trace.WriteLine(string.Format("browseButton location was incorrect:{0} for given rectangle:{1} with loc: {2}", browseButton.Location, borderedCellRectangle, loc));
                                browseButton.Location = loc;
                                changed = true;
                            }
                            if (changed)
                                browseButton.Invalidate();
                            if (!this.DataGridView.Controls.Contains(browseButton))
                                this.DataGridView.Controls.Add(browseButton);
                            borderedCellRectangle.Width -= browseButton.Width;
                        }
                    }
                    TextRenderer.DrawText(graphics, text, cellStyle.Font, borderedCellRectangle, thisCellIsSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor, flags);


                }
            }
            if ((base.DataGridView.ShowCellErrors) && ((paintParts & DataGridViewPaintParts.ErrorIcon) != DataGridViewPaintParts.None))
            {
                if ((!string.IsNullOrEmpty(errorText) && (cellValueBounds.Width >= 20)) && (cellValueBounds.Height >= 0x13))
                {
                    Rectangle iconBounds = this.GetErrorIconBounds(graphics, cellStyle, rowIndex);
                    if ((iconBounds.Width >= 4) && (iconBounds.Height >= 11))
                    {
                        iconBounds.X += cellBounds.X;
                        iconBounds.Y += cellBounds.Y;
                        Bitmap errorBitmap = new Bitmap(typeof(DataGridViewCell), "DataGridViewRow.error.bmp");
                        errorBitmap.MakeTransparent();
                        if (errorBitmap != null)
                        {
                            lock (errorBitmap)
                            {
                                graphics.DrawImage(errorBitmap, iconBounds, 0, 0, 12, 11, GraphicsUnit.Pixel);
                            }
                        }
                    }
                }

            }
            return empty;
        }

        public bool ShowFocusCues
        {
            get { return true; }
        }

        protected bool ApplyVisualStylesToHeaders
        {
            get
            {
                if (Application.RenderWithVisualStyles)
                {
                    return this.DataGridView.EnableHeadersVisualStyles;
                }
                return false;
            }
        }
        private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (base.Value.ToString().Length > 0)
            {
                System.Diagnostics.Process.Start(base.Value.ToString());
            }
        }
        void browseButton_Click(object sender, EventArgs e)
        {
            DataGridViewFilePathColumn filePathColumn = (DataGridViewFilePathColumn)this.DataGridView.Columns[ColumnIndex];
            if (filePathColumn.pathtype == DataGridViewFilePathColumn.PathType.file)
            {
                OpenFileDialog fdg = new OpenFileDialog();
                fdg.ShowDialog();
                base.Value = (fdg.FileName.Length > 0) ? fdg.FileName : base.Value;
            }
            else
            {
                FolderBrowserDialog fdg = new FolderBrowserDialog();
                fdg.ShowDialog();
                base.Value = (fdg.SelectedPath.Length > 0) ? fdg.SelectedPath : base.Value;
            }
        }
        public DataGridViewFilePathCell()
            : base()
        {
            browseButton = new Button();
            browseButton.Text = "…";
            browseButton.Click += new EventHandler(browseButton_Click); //yes, really two event handlers!
            //  base.DataGridView.CellClick +=DataGridView_CellClick;
        }
    }


000

111


ประวัติการแก้ไข
2015-10-26 17:40:29
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-26 17:36:34 By : lamaka.tor
 

 

No. 3



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



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


มีตัวอย่างที่เป็น VB.net ไหมครับ คุณ TOR_CHEMISTRY


ประวัติการแก้ไข
2015-10-28 15:06:08
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-28 15:05:45 By : TheCom
 


 

No. 4



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



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

http://codeconverter.sharpdevelop.net/SnippetConverter.aspx
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-28 15:18:40 By : lamaka.tor
 


 

No. 5



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



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


ตอบความคิดเห็นที่ : 2 เขียนโดย : lamaka.tor เมื่อวันที่ 2015-10-26 17:36:34
รายละเอียดของการตอบ ::
แจ่มเลยครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-28 15:18:50 By : fonfire
 


 

No. 6



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



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


ตอบความคิดเห็นที่ : 4 เขียนโดย : lamaka.tor เมื่อวันที่ 2015-10-28 15:18:40
รายละเอียดของการตอบ ::
ขอบคุณมากครับ

แต่มันติด Error ตรง
Dim filePathColumn As DataGridViewFilePathColumn = DirectCast(Me.DataGridView.Columns(ColumnIndex), DataGridViewFilePathColumn)
If filePathColumn.pathtype = DataGridViewFilePathColumn.PathType.file Then

browseButton.Click += New EventHandler(AddressOf browseButton_Click)



อันนี้ถ้าได้เราก็สารมารถไปเลือกเพิ่มได้จากตรง Property Add column ได้เลยใช่ไหมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-29 09:28:54 By : TheCom
 


 

No. 7



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



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

ตอบความคิดเห็นที่ : 6 เขียนโดย : TheCom เมื่อวันที่ 2015-10-29 09:28:54
รายละเอียดของการตอบ ::


เขาว่ากันว่า

https://www.thaicreate.com/community/csharp-datagridview-openfile-ban-ban.html

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-10-29 09:42:13 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามการสร้าง Button และ Textbox ใน 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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