I cannot make single column to be editable in DataGridView. I tried to do it in the designer but didn't get positive results. I tried scripting it like
datagridview1.Columns["theColumn"].ReadOnly=false;
but that didn't work. Seems like the property of ReadOnly in DataGridView is only that is considering, no other modifications count. I actually try to make DataGridViewColumn that contains CheckBoxes editable, while other columns I get from DataBase.
You can easily do it through the Edit Column wizard of the grid view, Go to edit column windows and select the columns that you want to make read only and in the right pane just set the ReadOnly property to true.
Visual Studio did not allow me to set single column ReadOnly property false when Enable Editing property of DataGridView is unchecked(???). But HOKBONG's comment helped. Thanks guys.
Related
I am using a "DevXpress.XtraGrid.GridView" and I have a column there which is bound to a boolean data. This column shows check boxes to represent values. I need to show "YES/NO" instead of check boxes. Please advice me.
Thanks for helping,
Kushan Randima.
This is how I do it in code in one of my tools. This is a dynamic SQL Query tool and it returns a checkmark or red X beside the query result, at runtime. You can also do this through the designer but this is done in code.
This is for Winforms, but the low level GridView should be the same code for WPF (I am not positive).
First, in the Data Grid GridView designer, I add a column (mine is "IsError" column). Then in my form constructor or InitializeForm() I do this:
RepositoryItemCheckEdit checkEdit = gridOutput.RepositoryItems.Add("CheckEdit") as RepositoryItemCheckEdit;
checkEdit.PictureChecked = global::Gyrasoft.Common.DX.Properties.Resources.exclamation;
checkEdit.PictureUnchecked = global::Gyrasoft.Common.DX.Properties.Resources.accept;
checkEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.UserDefined;
gridViewOutput.Columns["IsError"].ColumnEdit = checkEdit;
The resources, of course, have to be valid images.
Basically you add a repository item (RepositoryItemCheckEdit) and set CheckStyle to UserDefined, and assign the checkEdit to the gridView column. You can add the same checkedit to multiple columns. It is simply for rendering or editing.
On my Windows Form I have a DataGridView component, which is bound to a BindingSource. The BindingSource is an object datasource to an EntityFramework object.
Some times the columns in my DataBridView are renewed. Sometimes all properties are added as column, but now it also removed all my columns. So i've lost all my settings.
When to columns get automatically get added?
(I'm using VS.NET 2010)
Update:
//
// Summary:
// Gets or sets a value indicating whether columns are created automatically
// when the System.Windows.Forms.DataGridView.DataSource or System.Windows.Forms.DataGridView.DataMember
// properties are set.
//
// Returns:
// true if the columns should be created automatically; otherwise, false. The
// default is true.
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
[DefaultValue(true)]
public bool AutoGenerateColumns { get; set; }
The property did not show up in the designer, and "hide advanced properties" is not checked.
Update 2:
When I update my entity framework model, all columns are added again. I only can set the property in the constructor of the form. This is very annoying.
I actually don't know when this happens, but I tend to create all the columns manually. I create the columns in the designer and set the AutoGenerateColumns property to false in my code.
Add this code or change your DataGridView Property AutoGenerateColumns to false
DataGridView1.AutoGenerateColumns=false;
Set AutoGenerateColumns property to False but keep remember do it just before databinding.
eg:
DataGridView1.AutoGenerateColumns=false;
DataGridView1.DataSource=getData();
By default it is set to True.
Try leave first of auto generated columns and set it visibility false.
If it don't help try leave all them with Visible=false.
Sorry for bad English.
I had the same problem. I couldn't find the AutoGenerate property in my code.
For reasons I do not understand my DataGridView does not have an AutoGenerate property that I can see in my VB code.
I do not see a checkbox on the Edit Columns dialog box.
I do not see an AutoGenerate property in the grid's properties view.
I have Visual Studio Community 2017.
Here's my class properties:
Public Property BatchId As Integer
Public Property Code as String
Public Property Count As Integer
Public Property Description As String
Public Property Id As Integer
So, here's what I did:
I went to the form designer.
I right-clicked on the DataGridView.
I selected Edit Columns.
I made sure each column had the DataPropertyName field set to the class property name.
When I ran my application the DataGridView displayed only those columns in my class.
The little additional information provided by CoolBreeze was the item I was missing. I had created my columns in the designer so that I could do all the layout adjustments but then when I set the datasource property it would autogenerate the columns. I tried the suggestions about of setting the DataPropertyName in code but because I had the AutoGenerate set to false before doing that it was still putting the duplicate columns. Turns out I can set this property at design time as well and then set the AutoGenerate to false just prior to setting the DataSource and it works great.
I'm working on a windows forms app and there is a Janus GridEx component with 3 columns. I don't want users to change the values in the first two columns but I can't find the way to make readonly or allowedit false for the first two columns and third column editable.
I've tried changing the editmode but no luck either... anyone out there knows how?
Have you tried:
column.EditType = Janus.Windows.GridEX.EditType.NoEdit;
?
If you change the column's Selectable property to false, the user will not be able to edit it. You can set this property in the designer or in code. Here is an example which locks down the id column:
GridEXColumn idColumn = gridEX1.RootTable.Columns["id"];
idColumn.Selectable = false;
Again a c# question I cant't seem to figure out:
I have a datagridview on my form. In Visual Studio design mode, I enter 4 columns: refernce, country, name & city.
After a searchform is filled in, I try to refresh the datasource: A custom class fetches all the data from the selected table and fills the datagridview. The problem is: the datagridview now has all the columns of the table, and I only want the 4 columns entered in design mode.
I can put all the other columns on visible = false in design mode, and that works. But I want this datagridview as a custom control. So I only want to show the 4 entered columns, without disabling all the others. The data which is invisible is used to bind to a panel with other Controls like TextBoxes.
Does somebody know if this is possible, and how I should try to solve this?
Thanks!
You have three ways of hide columns.
1.- setting the visible property to false (as ksogor said) and don't create columns in design mode. Note that
GridView1.Columns["ColumnName"].Visible = false;
is more readable and mantenible that
GridView1.Columns[1].Visible = false;
2.- setting AutoGenerateColumns to false and create columns in the designer
3.- in your class, set the attribute [Browsable(false)] in the fields you don't want to show. Don't create columns in design mode.
The third way will hide the column in all the datagrids of your app. I love it.
[Browsable(false)]
public string Something{get;set;}
New to .NET/C# stuff so please forgive me if it's something obvious ;-) I'm trying to get cell editing going on a DataGridView control (WinForms). I've set all "ReadOnly"-type options to false, I've set EditMode to "EditOnEnter", I've added a row and selected a current cell programmatically, I've tried calling BeginEdit() but all to no avail - I can't edit the cell's contents.
The only thing that I can think of is that the control isn't bound to a data source - I'd like to be able to use it in a spreadsheet manner, so as the contents are typed in, I can then add new rows etc, and on a button click, the data can be retrieved programmatically for later use.
Is this possible?
Thanks,
Rich
I do that all the time (i.e. allowing users to edit a column without the DataGridView being bound).
Try this:
Set EditMode to EditOnKeystrokeOrF2
Ensure ReadOnly on the DataGridView is set to false
Ensure that ReadOnly on the column you want to edit is set to false
That should work.