This is a migrated thread and some comments may be shown as answers.

Some questions about radgridview

1 Answer 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 05 Sep 2012, 07:35 AM
Hi

I just discovered it's not possible to do what I originally wanted, so Im just going to tell what exactly I want to accomplish

1. Fill the content of a radgridview to the edges so I don't have empty space between the tablecontent and the tableborders, here's an ugly ascii representation
______________________________
|[column][column](space space space)|
|[cell......][cell......](space space space)|
|[cell......][cell......](space space space)|
|[cell......][cell......](space space space)|
|(space space space space space sp)|
|(space space space space space sp)|
|(space space space space space sp)|
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
instead I want the columns to stretch and empty rows be displayed instead of a white background, kinda like this
______________________________
|[column got stretched][column stretch]|
|[Cell stretched with it..][this cell too.....]|
|[Cell stretched with it..][this cell too.....]|
|[Cell with no data, it ju][st looks like....]| (...there's a row but all the cells have a white background)
|[Cell with no data, it ju][st looks like....]|
|[Cell with no data, it ju][st looks like....]|
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

2. I have a list of custom data objects (List<someObject>) basically I want it to automatically figure out that some properties goes to specific cells and others aren't shown, so if I have.
public class SomeObject
{
public string showthisString;
public DateTime showThisDate;
public int showThisInt;
public string dontshowthisstring;
public decimal showThisDec;
public int dontshowthisint;
}
and I create some columns I want to map showthisString to the column "MyAwesomeColumn" and showThisInt to "AwesomePoints". I am expecting code like this
public void InSomeMethod()
{
  DataTextColumn AwesomeCol = new DataTextColumn("UniquelyAwesome","who's awesome?") //uniquename, headerText
  AwesomeCol.readOnly=true; //if I wanted it readonly that is, just to display some sort of functionality change
  RadGridView grid; //for code block highlighting
  grid.Columns.Add(AwesomeCol)
  grid.Link.Link("showThisString","UniquelyAwesome");//when databinding it will find the showthisString property and map it to the column that has a uniquename of UniquelyAwesome
}

.net 4.0 and latest C# vs 2010

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 06 Sep 2012, 12:12 PM
Hello Anders,

RadGridView is capable of stretching the columns to fill the entire RadGridView estate area. This is done through the AutoSizeColumnsMode setting:

this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

As to the rows, RadGridView is not capable of showing empty rows that would fill the area where no real data rows are displayed.

In regards to your second enquiry about mapping columns, first I would like to let you know that RadGridView can automatically create columns and then you can just hide some of them using the following approach:
this.radGridView1.Columns.Remove(this.radGridView1.Columns["showthisString"]);
or you can just hide the column:
this.radGridView1.Columns["showthisString"].IsVisible = false;

In case you really want to create the columns on your own, you should first set the AutoGenerateColumns property to false (it is true by default):
this.radGridView1.AutoGenerateColumns = false;

Further, when creating the columns manually, you should set their FieldName in order to map them to the datasource properties:
GridViewTextBoxColumn myAwesomeColumn = new GridViewTextBoxColumn("UniquelyAwesome", "showthisString");
myAwesomeColumn.HeaderText = "who's awesome?";
this.radGridView1.Columns.Add(myAwesomeColumn);

I hope this helps.

All the best,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Anders
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or