I have a DataGridView on a Winforms form and, as usual, space is limited. The column titles are therefore often abbreviated ("Qty.", "No." etc.). My screenreader (JAWS) handles the DataGridView like a table and reads the column header as I navigate through the "cells" (i.e. the controls in the grid). Ideally, I would like to get the screenreader to use an accessible name for the header, so it would read "quantity" instead of "queue tea why".
I can't find an AccessibleName property for the column or the column header. Does anyone know where it is lurking, or is it simply not available?
I do not know much about JAWS but if you you have a space issue with your DGV columns why don't you set the column header DefaultCellStyle > WrapMode property to true, So that if you use more than one word in any column header text it can be wrapped. So you might be able to use meaningful column names instead of abbreviations.
I don't know how JAWS works, if you just need a property called AccessibleName you can create a new DataGridView Column class inheriting from DataGridViewTextBoxColumn
public class AccessibleDataGridViewTextBoxColumn : DataGridViewTextBoxColumn
{
public string AccessibleName { get; set; }
}
and adding them to your DataGridView. You can then set the property with your desired text in the designer or in your code.
Related
I have a datagridview configured to autogenerate columns based on my class (using databinding).
It works just fine for all my properties of type string. However, I have a property of an enum type, with a typeconverter to convert it to an image.
I'd like for my Grid's autogeneration of columns to produce a DataGridViewImageColumn instead of a DataGridViewTextBoxColumn.
The only DGV method that seems helpful is columns added. However, you cannot set the column there, only get & modify.
Any Ideas?
as far as i know, the AutoGeneration isn't very configurable
but you can make an alternative auto gen for yourself:
set autogen = false,
register to these events:
OnDataMemberChanged
OnDataSourceChanged
add a single function that will be triggered for both, which will create columns for the dataSource given:
header = column name
column type = according to what you want
data binding = the column name
etc.
I have a datagridview in my form. This datagridview has some columns. There are some custom columns (I have created custom datagridview cells). These custom cells have some properties that I want to do visible from datagridview's columns editor in design time in order to set them. So in design time, I open datagridview's columns editor, and I create a column of the custom datagridview cell. Then, I set some custom properties and I close datagridview's olumns editor. When I open the datagridview's columns editor, the values that I set previously for those custom properties are not reflected, it seems like they were not saved once datagridview's columns editor was closed. So... why? why the values for the custom properties are not saved? What Am i doing wrong?
Furthermore, I cannot leave as empty these custom properties because an exception I raised once form is loaded (object reference not set as a instance of an object).
I highly appreciate if someone could help me.
I ran into this identical issue. After searching, I found some feedback on a microsoft site that said I had to implement iCloneable in my datagridviewtextboxcolumn derivation.
You can find the article here and the relevant section:
In some rare cases, the column type may want to expose a property that
has no equivalent property at the cell level. Examples of that are
DataGridViewLinkColumn.Text and DataGridViewImageColumn.Image. In
those cases, the column class needs to override the Clone method to
copy over that property.
My column added four extra properties, and here's my icloneable function:
//Override this method to set the custom properties.
public override object Clone()
{
var col = base.Clone() as BauerDataGridViewTextBoxColumn;
col.ShowBorder = this.ShowBorder;
col.BorderColor = this.BorderColor;
col.ColumnChooserIsOptional = this.ColumnChooserIsOptional;
col.ColumnChooserColumnLabel = this.ColumnChooserColumnLabel;
return col;
}
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;}
In my Windows Mobile .NET application I have a simple array of object with the data I want to display in my DataGrid. To do this, I simply call:
myDataGrid.DataSource = myArray;
This works, but I have a problem with it: it uses all properties as columns and uses the names of the properties as the column headers. I can't figure out how to customize two things:
Select which subset of properties should be displayed as columns (say I have an ID, Name and Value property, I'd only want to show Name and Value);
Rename the column headers to make more sense (for example if the property is called ID display a column header saying "Number").
Is this possible at all?
As mentioned this is in a Windows Mobile .NET (version 2) application.
You need to set the Datagrid.TableStyles property to customize the layout.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid.tablestyles.aspx
More details on binding to an array of objects here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridtablestyle.mappingname(VS.71).aspx
To bind the
System.Windows.Forms.DataGrid to a
strongly typed array of objects, the
object must contain public properties.
To create a DataGridTableStyle that
displays such an array, set the
MappingName property to classname[]
where classname is replaced by the
class name. Also note that the
MappingName property is
case-sensitive.
I don't know if you know the name of the columns in advance? But if it's the case, you can go in the "Edit Columns" of your DataGridView and just create your columns there. In the "Data" Category, change the "DataPropertyName" from "(none)" to the name of the class property. From there you can customize the name, if it's visible, the size, etc. The DataGrid will bind it to your DataSource.
Also, there is a property "DataGridView.AutoGenerateColumns" that you can set to false so you don't have to bind all the properties of your object. I tought that migh help as well.
In this code _im is an object of table and I bind this object with DataGridView dgvItem after binding I change header text of dgvItem as required.
dgvItem.Rows.Clear();
dgvItem.DataSource = _im ;
dgvItem.Columns[2].HeaderText = "Mobile Code";
dgvItem.Columns[3].HeaderText = "Mobile Name";
I have a DataGridView in a C# WinForms app that is DataBound at runtime (through Form_Load) to a custom Object.
In the design view of the DataGridView I have no columns set up.
When the Form loads the the columns are automatically created based on the data in the Custom object that it is DataBound to.
My question is how can I control the the Columns that are automatically created.
For example if I want one of the columns to be a DataGridViewLinkColumn instead of the DataGridViewTextBoxColumn that is automatically created?
The default columns are based on the data-type. I haven't checked, but for a link you could try exposing the data as Uri, but that might be hopeful. Really, if you want a specific type of column - add the columns through code and set DataGridView.AutoGenerateColumns to false.
As Andrew implies; normally something like reflection is used to generate the columns, and you'll get a column for every (browsable + public + readable) property. There is a layer of abstraction on top of this if you need, but this won't help with adding a hyperlink column.
You can pre-create your columns in the designer. If the name of the column matches the name of the property the column will end up bound to, the databinding will take care of the DGV population for you as before.