Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to create Textbox with ellipse button

How to create Textbox with ellipse button

Scheduled Pinned Locked Moved C#
csharpwinformsmysqlvisual-studioalgorithms
19 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B BillWoodruff

    Hi Wayne, I think you are right ! Unless I can come up with a composite Control with TextBox and Button with Alt-0133 justified right, I'm going to remove my post. thanks, Bill

    “The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet

    A Offline
    A Offline
    ahmed_one
    wrote on last edited by
    #5

    Wayne is right... I am talking about ellipse button like ...

    1 Reply Last reply
    0
    • A ahmed_one

      Dear All, I am using Visual Studio 2010, C# and MySql. In one of my Winforms, there is a bound DataGridView which contains few textbox columns. I am looking for a solution to add an ellipse button in one of the Textbox column, upon clicking the ellipse button it will show a second form. I've no experience of creating any user controls, so upon searching on net, I found plenty of examples but due to the lack of knowledge I am unable to follow them. I am not looking for someone to spoon feed me, but some simple to advance tutorials/guidelines/sample will be highly appreciated. Thanks in advance Ahmed

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #6

      The easiest way (IMHO) is to simply create a user control that is a composite of a text box and the ellipses button.  Be sure to anchor the controls such that the button is right aligned and never changes in size. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      A 1 Reply Last reply
      0
      • R Ravi Bhavnani

        The easiest way (IMHO) is to simply create a user control that is a composite of a text box and the ellipses button.  Be sure to anchor the controls such that the button is right aligned and never changes in size. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        A Offline
        A Offline
        ahmed_one
        wrote on last edited by
        #7

        Ravi thanks for your post, as mentioned in my post, I am not familier with custom controls programming. Need some guidance/tutorial/sample, anything get me started... Thanks

        R 2 Replies Last reply
        0
        • A ahmed_one

          Ravi thanks for your post, as mentioned in my post, I am not familier with custom controls programming. Need some guidance/tutorial/sample, anything get me started... Thanks

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #8

          See this[^] link.  I believe there's a sample you can download. The actual task is quite simple: you create a User Control (Add New Item | User Control) which is essentially a canvas on which you can drag any number of controls (a la a Form). /ravi

          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

          B 1 Reply Last reply
          0
          • A ahmed_one

            Ravi thanks for your post, as mentioned in my post, I am not familier with custom controls programming. Need some guidance/tutorial/sample, anything get me started... Thanks

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #9

            And here's a full-blown, juicy CP article: File Searcher Edit Control with Browse Button[^]. Crap - it's not .NET.  My bad. :-O /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            A 1 Reply Last reply
            0
            • R Ravi Bhavnani

              And here's a full-blown, juicy CP article: File Searcher Edit Control with Browse Button[^]. Crap - it's not .NET.  My bad. :-O /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              A Offline
              A Offline
              ahmed_one
              wrote on last edited by
              #10

              Ravi thanks for link with sample....I will try it...and let u guys posted....

              R 2 Replies Last reply
              0
              • A ahmed_one

                Dear All, I am using Visual Studio 2010, C# and MySql. In one of my Winforms, there is a bound DataGridView which contains few textbox columns. I am looking for a solution to add an ellipse button in one of the Textbox column, upon clicking the ellipse button it will show a second form. I've no experience of creating any user controls, so upon searching on net, I found plenty of examples but due to the lack of knowledge I am unable to follow them. I am not looking for someone to spoon feed me, but some simple to advance tutorials/guidelines/sample will be highly appreciated. Thanks in advance Ahmed

                B Offline
                B Offline
                BillWoodruff
                wrote on last edited by
                #11

                A question I think you will need to answer here is whether or not a UserControl can be used in the DataGridView in a way that is satisfactory to you. Some years ago the DataGridView Program Manager at Microsoft wrote this:

                "There is no recommended way to do this. The DataGridView only supports hosting a user control as an editing control when a cell is in edit mode. Regarding shared rows/cells. When a row becomes unshared the grid raises the RowUnshared event. To unshare a row, the grid calls the row's clone method which in turn clones all its cells.

                For a databound grid, the cells to not get their values set since the cells do not store any data -- the underlying datasource stores the data. In the SetValue and GetValue code for a cell it checks to see if the cell/column/grid is databound and if so just retrieves or sets the value to the datasource. This is why you do not get a SetValue call with values as the grid is being displayed. The cell's GetValue method will be called as the grid is being displayed, so maybe you can use that?"

                Another possibility ... which I am not sure will work ... is the idea of sub-classing a TextBox but putting a Label, or Button, inside it which you can wire-up to get the Click Event. Yes, you can create such a composite Component; I have done so, and used it successfully. But, the question is: will the DataGridView allow you to put such a sub-classed TextBox in one of its TextBox Columns ? If someone here with more experience with the DataGridView can answer the question if such a sub-classed Component can be used, I'll be happy to post an example.

                “The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet

                A 1 Reply Last reply
                0
                • A ahmed_one

                  Ravi thanks for link with sample....I will try it...and let u guys posted....

                  R Offline
                  R Offline
                  Ravi Bhavnani
                  wrote on last edited by
                  #12

                  Also see this CP solution: How to place the UserControl(textbox + Button) inside the datagridview[^]. /ravi

                  My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                  1 Reply Last reply
                  0
                  • R Ravi Bhavnani

                    See this[^] link.  I believe there's a sample you can download. The actual task is quite simple: you create a User Control (Add New Item | User Control) which is essentially a canvas on which you can drag any number of controls (a la a Form). /ravi

                    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                    B Offline
                    B Offline
                    BillWoodruff
                    wrote on last edited by
                    #13

                    Hi Ravi-ji, That example shows creating a UserControl; please see my last post on this thread which quotes the MS DataGridView Program Manager (several years ago) on using UserControls in the DataGridView. I'd appreciate your opinion on whether the ... to my mind ... limitations described there would rule out the kind of usage that Ahmed may want. Also appreciate your opinion on my hypothetical proposal to try and use a sub-classed TextBox (a Component) in a DataGridView TextBox Column. thanks, Bill

                    “The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet

                    R 1 Reply Last reply
                    0
                    • A ahmed_one

                      Ravi thanks for link with sample....I will try it...and let u guys posted....

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #14

                      And here[^] is a full solution at MSDN. /ravi

                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                      1 Reply Last reply
                      0
                      • B BillWoodruff

                        A question I think you will need to answer here is whether or not a UserControl can be used in the DataGridView in a way that is satisfactory to you. Some years ago the DataGridView Program Manager at Microsoft wrote this:

                        "There is no recommended way to do this. The DataGridView only supports hosting a user control as an editing control when a cell is in edit mode. Regarding shared rows/cells. When a row becomes unshared the grid raises the RowUnshared event. To unshare a row, the grid calls the row's clone method which in turn clones all its cells.

                        For a databound grid, the cells to not get their values set since the cells do not store any data -- the underlying datasource stores the data. In the SetValue and GetValue code for a cell it checks to see if the cell/column/grid is databound and if so just retrieves or sets the value to the datasource. This is why you do not get a SetValue call with values as the grid is being displayed. The cell's GetValue method will be called as the grid is being displayed, so maybe you can use that?"

                        Another possibility ... which I am not sure will work ... is the idea of sub-classing a TextBox but putting a Label, or Button, inside it which you can wire-up to get the Click Event. Yes, you can create such a composite Component; I have done so, and used it successfully. But, the question is: will the DataGridView allow you to put such a sub-classed TextBox in one of its TextBox Columns ? If someone here with more experience with the DataGridView can answer the question if such a sub-classed Component can be used, I'll be happy to post an example.

                        “The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet

                        A Offline
                        A Offline
                        ahmed_one
                        wrote on last edited by
                        #15

                        Ravi thanks again for all links....and thanks BillWoodRuff I will appreciate if u can post the sample....

                        B 1 Reply Last reply
                        0
                        • B BillWoodruff

                          Hi Ravi-ji, That example shows creating a UserControl; please see my last post on this thread which quotes the MS DataGridView Program Manager (several years ago) on using UserControls in the DataGridView. I'd appreciate your opinion on whether the ... to my mind ... limitations described there would rule out the kind of usage that Ahmed may want. Also appreciate your opinion on my hypothetical proposal to try and use a sub-classed TextBox (a Component) in a DataGridView TextBox Column. thanks, Bill

                          “The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet

                          R Offline
                          R Offline
                          Ravi Bhavnani
                          wrote on last edited by
                          #16

                          Yeah, I also posted a link to the PM's post

                          BillWoodruff wrote:

                          hypothetical proposal to try and use a sub-classed TextBox (a Component) in a DataGridView TextBox Column.

                          I think it might be better to subclass a DataGridViewTextBoxColumn[^].  What do you think? /ravi

                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                          1 Reply Last reply
                          0
                          • A ahmed_one

                            Ravi thanks again for all links....and thanks BillWoodRuff I will appreciate if u can post the sample....

                            B Offline
                            B Offline
                            BillWoodruff
                            wrote on last edited by
                            #17

                            I have no idea if this is usable in a DataGridView in place of the TextBox normally used in a TextBox Column, but it was fun to write. Once you get a feeling for how easy it is to make new Controls (UserControls), or sub-class existing Controls (make Components), you can develop hybrids for special purposes very easily. The "craft" in it is getting the alignments and re-sizing right.

                            using System;
                            using System.ComponentModel;
                            using System.Drawing;
                            using System.Windows.Forms;

                            namespace March17_StateTracking
                            {
                            public partial class TBEllipse : TextBox
                            {
                            // necessary to define this in Component scope
                            // for MouseHover and MouseLeave EventHandlers
                            // to work properly
                            private readonly Label tLabel;

                                // expose the Label for external use
                                public Label TheLabel { set; get; }
                            
                                public TBEllipse()
                                {
                                    InitializeComponent();
                            
                                    tLabel = new Label();
                                    TheLabel = tLabel;
                            
                                    tLabel.Text = "…";
                            
                                    tLabel.FlatStyle = FlatStyle.Flat;
                                    tLabel.BorderStyle = BorderStyle.None;
                                    tLabel.BackColor = Color.Gainsboro;
                                    tLabel.TextAlign = ContentAlignment.TopRight;
                                    tLabel.Margin = new Padding(0, 0, 0, 0);
                                    tLabel.AutoSize = true;
                            
                                    Controls.Add(tLabel);
                                    tLabel.Left = Width - tLabel.Width;
                                    tLabel.Show();
                                    tLabel.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
                            
                                    tLabel.MouseClick += tLabel\_MouseClick;
                                    tLabel.MouseHover += tLabel\_MouseHover;
                                }
                            
                                public TBEllipse(IContainer container)
                                {
                                    container.Add(this);
                            
                                    InitializeComponent();
                                }
                            
                                private void tLabel\_MouseClick(object sender, MouseEventArgs e)
                                {
                                    tLabel.BackColor = Color.Gainsboro;
                                }
                            
                                private void tLabel\_MouseHover(object sender, EventArgs e)
                                {
                                    tLabel.BackColor = Color.Lime;
                                }
                            }
                            

                            }

                            After creating an instance of this ... you can test it by drag-dropping it from the ToolBox to a Form after it is compiled ... you can subscribe to the Click Event of the Label. Here's an example of creating an instance in code and adding it to a Form's ControlCollection when a Button on the Form is clicked:

                            private void TestTBEllipse_Click(object sender, EventArgs e)
                            {
                            TBEllipse testTBEllipse = new TBEllipse();
                            testTBEllips

                            1 Reply Last reply
                            0
                            • A ahmed_one

                              Dear All, I am using Visual Studio 2010, C# and MySql. In one of my Winforms, there is a bound DataGridView which contains few textbox columns. I am looking for a solution to add an ellipse button in one of the Textbox column, upon clicking the ellipse button it will show a second form. I've no experience of creating any user controls, so upon searching on net, I found plenty of examples but due to the lack of knowledge I am unable to follow them. I am not looking for someone to spoon feed me, but some simple to advance tutorials/guidelines/sample will be highly appreciated. Thanks in advance Ahmed

                              A Offline
                              A Offline
                              Alan N
                              wrote on last edited by
                              #18

                              Why not just add a column of buttons next to the text column. The simplest and easiest way to do this would be to add an unbound DataGridViewButtonColumn to the DataGridView in the DataBindingComplete event and then handle the CellContentClick event to respond to button clicks. Sample event handlers for a DataGridView 'dgv' on a Form 'Form1'

                              int buttonColumnIndex; // to identify the button column in the CellContentClick handler

                              public Form1() {
                              InitializeComponent();
                              // add the event handlers
                              dgv.CellContentClick += new DataGridViewCellEventHandler(dgv_CellContentClick);
                              dgv.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dgv_DataBindingComplete);
                              }

                              private void dgv_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) {
                              DataGridViewButtonColumn bc = new DataGridViewButtonColumn();
                              bc.Name = "ButtonColumn";
                              bc.HeaderText = "";
                              bc.UseColumnTextForButtonValue = true;
                              bc.Text = "Edit";
                              bc.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                              buttonColumnIndex = dgv.Columns.Add(bc);
                              // Column will be at the right, move to the required position
                              // e.g move to left
                              dgv.Columns[buttonColumnIndex].DisplayIndex = 0;
                              }

                              private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) {
                              if (e.ColumnIndex == buttonColumnIndex) {
                              MessageBox.Show(String.Format("Edit button clicked on row {0}", e.RowIndex));
                              }
                              }

                              Alan...

                              A 1 Reply Last reply
                              0
                              • A Alan N

                                Why not just add a column of buttons next to the text column. The simplest and easiest way to do this would be to add an unbound DataGridViewButtonColumn to the DataGridView in the DataBindingComplete event and then handle the CellContentClick event to respond to button clicks. Sample event handlers for a DataGridView 'dgv' on a Form 'Form1'

                                int buttonColumnIndex; // to identify the button column in the CellContentClick handler

                                public Form1() {
                                InitializeComponent();
                                // add the event handlers
                                dgv.CellContentClick += new DataGridViewCellEventHandler(dgv_CellContentClick);
                                dgv.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dgv_DataBindingComplete);
                                }

                                private void dgv_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) {
                                DataGridViewButtonColumn bc = new DataGridViewButtonColumn();
                                bc.Name = "ButtonColumn";
                                bc.HeaderText = "";
                                bc.UseColumnTextForButtonValue = true;
                                bc.Text = "Edit";
                                bc.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                                buttonColumnIndex = dgv.Columns.Add(bc);
                                // Column will be at the right, move to the required position
                                // e.g move to left
                                dgv.Columns[buttonColumnIndex].DisplayIndex = 0;
                                }

                                private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) {
                                if (e.ColumnIndex == buttonColumnIndex) {
                                MessageBox.Show(String.Format("Edit button clicked on row {0}", e.RowIndex));
                                }
                                }

                                Alan...

                                A Offline
                                A Offline
                                ahmed_one
                                wrote on last edited by
                                #19

                                Thanks Alan, I am at present using button column. Actually this textbox with button idea is the inspiration from some popular Accounting softwares. They use in variety of there data entry forms, like for e.g Invoice, when user enter line item, there is column ProductID, when user enters ProductID column he/she can directly enter Product ID or use the ellipse button to show a lookup form. This looks cool, so I thought may be there are some ways we can do it in C# winforms, and by the look of all posts here I am now sure there are more then one ways. Thanks to all for helping me..I am trying to learn to create custom control, and if there is no success I will stick to button column approach.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups