Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2005

Tip: Looking for answers? Try searching our database.

Binding combobox to a cell of a datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
geeta - 27 Oct 2005 08:39 GMT
hi,

i am facing problem with attaching combobox to a cell of a datagrid. namely
to the cell 3rd row 4 column..
then the combobox should display the content of that particular cell...

can anyone help me in this regard

Thanks
Geeta
Bajoo - 28 Oct 2005 13:43 GMT
Dear Geeta,
                    what I have understood from ur question, the
following code might help you in ur task. It binds a ArrayList to a
combobox and then attaches the comboBox to the DataGrid

            DataGridTableStyle ts = new DataGridTableStyle();
            ts.MappingName = "ArrayList";

            int colwidth = (this.dataGrid1.ClientSize.Width
                - ts.RowHeaderWidth
                - SystemInformation.VerticalScrollBarWidth - 2) / 2;

            // Create a column for the "Name" property
            // defined in the EntityField Class
            DataGridTextBoxColumn cs = new DataGridTextBoxColumn();
            cs.MappingName = "FieldName";  // Public property name
            cs.HeaderText = "Field Name";
            cs.Format = "f4";
            cs.Width = colwidth;
            cs.ReadOnly=true;
            ts.GridColumnStyles.Add(cs);

            cs = new DataGridTextBoxColumn();
            cs.MappingName = "Order";  // Public property name
            cs.HeaderText = "Order";
            cs.Format = "f4";
            cs.Width = colwidth;
            cs.ReadOnly=true;
            ts.GridColumnStyles.Add(cs);
            // Add the custom tablestyle to the DataGrid
            this.dataGrid1.TableStyles.Clear();
            this.dataGrid1.TableStyles.Add(ts);
            this.dataGrid1.DataSource =lstOrderByFields;
            DataGridTextBoxColumn datagridtextBox=
(DataGridTextBoxColumn)this.dataGrid1.TableStyles[0].GridColumnStyles[1];
            //for(int j=0;j<lstTables.Count;j++)

            cmb=new ComboBox();
            cmb.Height=datagridtextBox.TextBox.Height;
            cmb.Width=colwidth;

            cmb.DropDownStyle=ComboBoxStyle.DropDownList;
            cmb.Items.Add(ASCENDING);
            cmb.Items.Add(DESCENDING);
            cmb.Dock=DockStyle.Fill;
            cmb.SelectedIndexChanged+=new
EventHandler(cmb_SelectedIndexChanged);
            datagridtextBox.TextBox.Controls.Add(cmb);

I hope it helps.

Regards,
Naveed Ahmad Bajwa
Kalsoft Pvt Ltd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.