GridListControl - Order of Columns and accessing Selected Row

I had added this post to the previous thread that I had started and I suspected that it would be lost there so I am re-posting it

Hi Saravanan

I need to have some control over the order of columns that appear in the GridListControl.

At the moment I am not able to find out on what basis does the GridListcontrol order the columns.

Just to refresh your memory I am using Gridlistcontrol as a celltype in the gridcontrol.

The datasource is a list which is populated thru a datareader.

I read some in the forumn that deriving gridlistcontrol and overriding CreateGridColumn should do the job, but that isnt working out for me.

Your previous advice helped a lot. I was also able to align and format the columns.

One more thing. How does one access in code the row selected in the GridListControl.

Thanks & Best Regards
RH



>HI Saravanan

Thanks ! This solves two remaining issues...

It also gives me sufficient inputs to try to solve some more issues which have come up in the meanwhile

>Hi RH,

1, Change the column headings that i am getting in the dropdown gridlist.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

This can be achieved by changing the cellvalues of the header cells. For this, PrepareViewStyleInfo event of the underlying gridcontrol can be used.
Here is the code snippet.
//In form load
GridDropDownGridListControlCellRenderer renderer = this.gridControl1.CellRenderers["GridListControl"] as GridDropDownGridListControlCellRenderer;
renderer.ListControlPart.Grid.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(Grid_PrepareViewStyleInfo);
..
void Grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (e.RowIndex == 0)
{
if (e.Style.CellValue.ToString() == "col2")
{
e.Style.CellValue = "Column2";
}
}
}

2, I need to optionally hide some columns
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Any columns of gridlistcontrol celltype in gridcontrol can be made hidden from the 'CurrentCellShowingDropDown' Event of gridcontrol.
Here is the code snippets.
void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
GridDropDownGridListControlCellRenderer renderer = cc.Renderer as GridDropDownGridListControlCellRenderer;
if (renderer != null)
{
renderer.ListControlPart.Grid.HideCols["columnName"] = true;
}
}

Regards,
Saravanan

1 Reply

RA Rajagopal Syncfusion Team March 27, 2007 05:25 PM UTC

Hi RH,

Question 1:

Please refer this forum thread that discusses controlling the order of columns in GridListControl.
http://www.syncfusion.com/support/Forums/message.aspx?MessageID=26398

Question 2: Accessing selected row

You can use the code below in the CurrentCellCloseDropDown event to get the selected row in the GridListControl dropdown.

void gridControl1_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
GridDropDownGridListControlCellRenderer cr = cc.Renderer as GridDropDownGridListControlCellRenderer;
if (cr != null)
{
Console.WriteLine("Selected Value: {0}", cr.ListControlPart.SelectedValue);
DataRow dr = ((DataRowView)cr.ListControlPart.SelectedItem).Row;
Console.WriteLine(dr[0].ToString());
Console.WriteLine("Selected RowIndex: {0}", cr.ListControlPart.SelectedIndex);
}
}

Please let us know if you need any further help.
Regards,
Rajagopal

Loader.
Up arrow icon