Reputation: 1
I'm developing a Winform application that contains a Devexpress GridView composed as follow:
Location
and Hotel Name
column)I have this data in input: Location Name
, Hotel name
.
When I open the form I need to expand the corresponding group for the location and hotel name and open the detail view with the availability for that hotel.
In the attachment you can find the screenshot of the grid with the row expanded as I need.
Can you help me do that?
The code that I have tried is the following, but it only opens the Location group and not the Hotel name and it's details.
private void hotelAvailabilityGridView_EndGrouping(object sender, EventArgs e)
{
FocusFirstRecordInGroupRow(_hotelName);
}
public void FocusFirstRecordInGroupRow(string textToFind)
{
int groupRow = FindGroupRow(_hotelName);
if (groupRow >= 0) return;
hotelGridView.ExpandGroupRow(groupRow);
hotelGridView.FocusedRowHandle = hotelGridView.GetChildRowHandle(groupRow, 0);
}
private int FindGroupRow(string textToFind)
{
int i = 1;
while (i != GridControl.InvalidRowHandle)
{
i--;
string value = hotelGridView.GetGroupRowValue(i, hotelGridView.Columns[0]).ToString();
if (value == textToFind)
{
RecursExpand(hotelGridView, i);
return i;
}
}
return 0;
}
The screenshot:
Upvotes: 0
Views: 1437
Reputation: 18290
I suggest you go through documentation of Process Group Rows
You can check whether it is group row using below method of view:
int rowHandle = view.FocusedRowHandle;
if(view.IsGroupRow(rowHandle)){}
After that, you can set it expands status:
bool expanded = View.GetRowExpanded(rowHandle);
View.SetRowExpanded(rowHandle, !expanded);
You can locate a row by value as below, You can expand matched row and collapse others as you require.
using DevExpress.XtraGrid.Views.Grid;
//...
GridView View = gridView1;
int rowHandle = -1;
do {
rowHandle = View.LocateByValue(rowHandle+1, View.Columns["Is In Stock"], false);
View.MakeRowVisible(rowHandle, false);
} while(rowHandle != GridControl.InvalidRowHandle);
References:
How to select only group rows in XtraGrid with multi-select mode?
Group rows in a gridview
Selecting row in a grouped grid
Upvotes: 0