DataGrid from bindingSource collumn width

L

lodzik

Hi,
I can't make this style visible. I'm new in coding but I readed every
post about that and have still problem.
My code looks like this:

DataGridTableStyle myGridStyle = new DataGridTableStyle();
myGridStyle.MappingName = "lineBindingSource";

DataGridTextBoxColumn idColumn = new DataGridTextBoxColumn();
idColumn.MappingName = "ID";
idColumn.HeaderText = "Test";
idColumn.Width = 240;
myGridStyle.GridColumnStyles.Add(idColumn);

dataGrid1.TableStyles.Add(myGridStyle);

Any idea what is wrong?
 
I

Ilya Tumanov [MS]

1. Wrong table mapping name - for DataTable should be table name, for pretty
much everything else should be empty string.
2. Wrong column mapping name - no column called "ID"


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
R

Rüdiger Kardel

a

dataGrid1.TableStyles.Clear();
is missing before
dataGrid1.TableStyles.Add(myGridStyle);

Ruediger
 
R

Rüdiger Kardel

is there a

dataGrid1.DataSource = aDataTableOrSth

missing?

last but not least:
if you are using a datatable as datasource: the mappingname is
casesensitive.

if it didn't work either:
show us some more code, please.

Ruediger
 
L

lodzik

I have a variable file which is collection of objects (my own class
Line). In Form_Load event I have the following code:

DataGridTableStyle myGridStyle = new DataGridTableStyle();
myGridStyle.MappingName = "";

DataGridTextBoxColumn idColumn = new DataGridTextBoxColumn();
idColumn.MappingName = "ID";
idColumn.HeaderText = "Test";
idColumn.Width = 240;
myGridStyle.GridColumnStyles.Add(idColumn);

dataGrid1.TableStyles.Add(myGridStyle);

lineBindingSource.DataSource = file;

I have:

public class Line
{

/* some stuff */

public int ID
{
get { return id; }
set { id = value; }

}
}

class File : IEnumerable
{

/* some stuff */

List<Line> lines = new List<Line>();

#region IEnumerable Members

public IEnumerator GetEnumerator()
{
return lines.GetEnumerator();
}

#endregion
}

DataGrid1 contains all data, but I couldn't set the column width.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top