DataGrid Column Width using SqlCeResultSet

S

SarahP

Hi,

FYI I'm writing in C#, not VB.

I'm using an SqlCeResult set as the datasource for my datagrid. I need
to do this, for performance reasons, rendering the datagrid when its
datasource is a dataset takes 10X longer, and that makes a big
difference when you're dealing with 5000 records.

Anyways, I need to resize the columns within the datagrid. Since im
using a SqlCeResultSet and not a dataSet, DataGridTableStyles are
unusable. (Or if I'm wrong correct me and show me how to map them!!).

Is it AT ALL possible to change the size of the columns in this
situation? I have not been able to find this answer anywhere.

Thanks!
 
I

Ilya Tumanov [MS]

DataGridTableStyles/DataGridColumnStyles is usable the same way as with
DataSet.

In fact, they are completely data source independent. What kind of problems
you're having with these styles?


--
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).
 
S

SarahP

Hi,

Ok I figured it out, and for all the other postings I have seen on
message boards, this is how I fixed it:

When indicating the mappingName for the DataGridTableStyle, leave it
blank. When indicating the MappingName for the DataGridTextBoxColumn,
set it to the corresponding column name from your sql table.

Example:

SqlCeResultSet rs = new sqlcecommand("select c1 from table1",
sqlceconnection).ExecuteResultSet(options);
Datagrid dg = new datagrid;

DataGridTableStyle dgTabStyle = new DataGridTableStyle();
dgTabStyle.MappingName = ""; // notice its blank!!

// c1 Column
DataGridTextBoxColumn dgCol = new DataGridTextBoxColumn();
dgCol.MappingName = "c1";
dgCol.HeaderText = "Special Header";
dgCol.Width = 50;
dgTabStyle.GridColumnStyles.Add(dgCol);

dg.TableStyles.Add(dgTabStyle);

dg.datasource = rs;

Now you're datagrid should have all the formatting you want! without
the crappy performance of a dataset!

Hope this helps someone else!!
 
N

Norra

This was exactly what I was looking for I was able to do this by doing the following which may be helpful to others as well.
rsSum = cmd.ExecuteResultSet(ResultSetOptions.Scrollable)
Dim dgts As New DataGridTableStyle
dgts.MappingName = ""
'Columns
For col As Int32 = 0 To rsSum.FieldCount - 1
Dim dgCol As New DataGridTextBoxColumn
dgCol.MappingName = rsSum.GetName(col)
dgCol.HeaderText = dgCol.MappingName
Select Case dgCol.MappingName
Case "Col1", "Col5"
dgCol.Width = 60
Case "Col3"
dgCol.Width = 90
Case "Col2", "Col4"
dgCol.Width = 120
End Select
dgts.GridColumnStyles.Add(dgCol)
Next col
dgSum.TableStyles.Add(dgts)
'Bind the result set to the DataGrid
dgSum.DataSource = rsSum.ResultSetView

From http://www.developmentnow.com/g/18_2006_8_0_0_813636/DataGrid-Column-Width-using-SqlCeResultSet.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 

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