0
votes

I have a window form that has a datagridview. In this datagridview i am adding two columns dynamically as shown in below code.My problem is that when i click on these added columns ,Multiselect property is not selecting full row but when i click on first column of grid it selected full row.

 if (gvlayoutload.Columns.Count == 0)
                {
                    DataGridViewTextBoxColumn comboBoxColumnRInfo =
                          new DataGridViewTextBoxColumn();

                    comboBoxColumnRInfo.Name = "RowInfo";
                    comboBoxColumnRInfo.HeaderText = "";
                    comboBoxColumnRInfo.DataPropertyName = "RowInfo";
                    comboBoxColumnRInfo.ReadOnly = true;
                    comboBoxColumnRInfo.Width = 25;
                    comboBoxColumnRInfo.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    //comboBoxColumnRInfo.Frozen = true;
                    this.gvlayoutload.Columns.Add(comboBoxColumnRInfo);

                    DataGridViewTextBoxColumn comboBoxColumn =
                          new DataGridViewTextBoxColumn();

                    comboBoxColumn.HeaderText = "Row #";
                    comboBoxColumn.DataPropertyName = "RowNo";
                    comboBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
                    comboBoxColumn.Width = 45;
                    comboBoxColumn.FillWeight = 45;
                    //comboBoxColumn.Frozen = true;
                    FRColumn col = new FRColumn();
                    col.Name = comboBoxColumn.HeaderText;
                    col.Type = 1;
                    col.Variable1 = variable1;
                    col.Variable2 = variable2;
                    col.Percent = Percent;
                    col.Rowno = Rowno;
                    col.Headersize = 8;
                    col.Bodysize = 8;
                    col.HeaderAlign = 0;
                    col.BodyAlign = 0;
                    lstcolumn.Add(col);
                    this.gvlayoutload.Columns.Add(comboBoxColumn);

When i click on RowInfo column or Row # column Multiselect property not selected full row.I have set multiselect property to true and multiselection mode is fullrowmode.

1

1 Answers

0
votes

The DataGridView.SelectionMode property indicates how the cells of the DataGridView can be selected. The default value is RowHeaderSelect. The behavior of each mode is described in this MSDN link.

The first column in the DataGridView contains the row headers. If you select any cell in this column it will select the full row when the SelectionMode is RowHeaderSelect or FullRowSelect.

If you want to select multiple rows then set the DataGridView.MultiSelect = true.

You can also hide that column by setting DataGridView.RowHeadersVisible = false.