Code Monkey home page Code Monkey logo

Comments (2)

davidegironi avatar davidegironi commented on May 28, 2024

Hello,

A ComboBox is not an elementary type, so it's not handled by AdvancedDataGridView. Anyway there are a couple of trick you could use:

build a combobox and it's datatable source, with the ValueMember of type int. Then add an int value to the datagridview datatable of value int with the same name.

Taking the sample project as reference, something like below should work: SetTestData()

        private void SetTestData()
        {
            _dataTable = _dataSet.Tables.Add("TableTest");
            _dataTable.Columns.Add("int", typeof(int));
            _dataTable.Columns.Add("decimal", typeof(decimal));
            _dataTable.Columns.Add("double", typeof(double));
            _dataTable.Columns.Add("date", typeof(DateTime));
            _dataTable.Columns.Add("datetime", typeof(DateTime));
            _dataTable.Columns.Add("string", typeof(string));
            _dataTable.Columns.Add("boolean", typeof(bool));
            _dataTable.Columns.Add("guid", typeof(Guid));
            _dataTable.Columns.Add("image", typeof(Bitmap));
            _dataTable.Columns.Add("timespan", typeof(TimeSpan));
            // add the int reference to combobox
            _dataTable.Columns.Add("cmdview", typeof(int));

            bindingSource_main.DataMember = _dataTable.TableName;

            advancedDataGridViewSearchToolBar_main.SetColumns(advancedDataGridView_main.Columns);

            // add the combobox
            DataTable cmdDataSource = new DataTable();
            cmdDataSource.Columns.AddRange(new DataColumn[] { new DataColumn("Value", typeof(int)), new DataColumn("Display", typeof(string)) });
            cmdDataSource.Rows.Add(0, "cmb 0");
            cmdDataSource.Rows.Add(1, "cmb 1");
            cmdDataSource.Rows.Add(2, "cmb 2");
            DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
            cmb.HeaderText = "combobox";
            cmb.DataSource = cmdDataSource;
            cmb.DisplayMember = "Display";
            cmb.ValueMember = "Value";
            cmb.DataPropertyName = "cmdview";
            advancedDataGridView_main.Columns.Add(cmb);
            // disable the int reference view on datagrid view
            advancedDataGridView_main.Columns["cmdview"].Visible = false;
        }

Also don't forget to add a test value in the newrow object of the AddTestData() method. For testing purpose just select a value between 0 and 2 using r.Next(0, 2)

                        TimeSpan.FromHours(10).Add(TimeSpan.FromMinutes(r.Next(maxMinutes))),
                        // select a random value for the combobox view
                        r.Next(0, 2)
                    };

Another way could be override the CellValueChanged of the DataGridView to repait the value as a combobox, but it takes more resources.

from advanceddatagridview.

cadmonkey123 avatar cadmonkey123 commented on May 28, 2024

that worked thanks!

from advanceddatagridview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.