We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Model_QueryCellInfo

Thread ID:

Created:

Updated:

Platform:

Replies:

87971 Jul 13,2009 02:48 PM UTC Jul 16,2009 07:19 AM UTC WPF 9
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On July 13, 2009 02:48 PM UTC

Hi

I'm using the GridControl sample that shows range selections. Is there any way within the Model_QueryCellInfo event to obtain a reference to the GridControl that it is from? My scenario is of a dynamic number of grids so I need to be abl eto back-track to the owning grid to check for specific contidions.

Many thanks


Paul Eden

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On July 14, 2009 07:30 AM UTC

Hi Paul,

Thanks for the details. You can get the reference of the grid in the event arguments itself,

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
var grid = (GridControl)sender;
if (e.Cell.RowIndex == 0 && e.Cell.ColumnIndex > 0)
{
e.Style.Text = GridRangeInfo.GetAlphaLabel(e.Cell.ColumnIndex);
}
else if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex == 0)
{
e.Style.Text = e.Cell.RowIndex.ToString();
}
}

Please let me know if you need any more details.

Thanks,
Fahad
Grid.WPF Team
Syncfusion Inc.,

Administrator [Syncfusion]
Replied On July 14, 2009 09:46 AM UTC

Hi

I had already tried casting the sender but as the sender is a GridModel the following exception occurs:

Cannot cast 'sender' (which has an actual type of 'Syncfusion.Windows.Controls.Grid.GridModel') to 'Syncfusion.Windows.Controls.Grid.GridControl'


var grid = sender as GridControl produces a null value.


Many thanks

Paul

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On July 14, 2009 09:49 AM UTC

Hi Paul,

I was initially thinking that you were using the GridControl.QueryCellInfo event, You can use this too for your purpose.

If you want to access the GridControl from GridModel, then you could do it as below,

Model.CurrentCellState.GridControl

Or iterate the Views collection if you have multiple Grids attached to a single model,

foreach(var grid in Model.Views){

}

Please let me know if you need any more details.

Thanks,
Fahad
Grid.WPF Team
Syncfusion Inc.,

Administrator [Syncfusion]
Replied On July 14, 2009 10:28 AM UTC

Hi

Thanks for the reply.

When using
(GridModel)sender).CurrentCellState.GridControl

the GridControl property is null.

Is there anything else that shold be done?

Many thanks


Paul

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On July 14, 2009 10:30 AM UTC

Hi Paul,

The CurrentCellState will be available when the grid control is attached to the Model, Best way is to iterate the Views collection, that should give you the GridControl reference directly.

Thanks,
Fahad
Grid.WPF Team
Syncfusion Inc.,

Administrator [Syncfusion]
Replied On July 14, 2009 11:59 AM UTC

Hi

Ok, that worked, but it has knoecked on to another issue.

I generate a tab control of (n) tabItems and have 1 grid on each tabItem, generates as follows:

foreach(IWorksheet sheet in workBook.Worksheets)
{
//' create grid
grdSheet = new GridControl();
grdSheet.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo);
grdSheet.Model.RowCount = sheet.UsedRange.Rows.Count();
grdSheet.Model.ColumnCount = sheet.UsedRange.Columns.Count();
grdSheet.Model.ColumnWidths[0] = 30;
grdSheet.Model.Options.ExcelLikeCurrentCell = true;
grdSheet.Model.Options.ExcelLikeSelectionFrame = true;
grdSheet.Tag = sheet.Name;

//' create tab for sheet
TabItem tbiSheet = new TabItem();

tbiSheet.Header = sheet.Name;
tbiSheet.Content = grdSheet;

tbSheets.Items.Add(tbiSheet);

grdSheet = null;

}


void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.Cell.RowIndex == 0 && e.Cell.ColumnIndex > 0)
{
e.Style.Text = GridRangeInfo.GetAlphaLabel(e.Cell.ColumnIndex);
}
else if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex == 0)
{
e.Style.Text = e.Cell.RowIndex.ToString();
}
else if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex > 0)
{
e.Style.Text = workBook.Worksheets[((TabItem)((GridModel)sender).Views.First().Parent).Header.ToString()].Range[e.Cell.RowIndex, e.Cell.ColumnIndex].Value;
}
}

The trouble is that the Model_QueryCellInfo event only seems to fire for the first grid created; not even the A/1 Column/row headings are getting generated for the others. At first I thought this may be because the grids only get populated when they're drawn on the screen and being on non-active tabItems would mean they're not getting drawn, but when clicking on another tab, still the relevent Model_QueryCellInfo event does not fire.

Am I missing something in my undertsanding (not impossible :) )?

Many thanks


Paul

Clay Burch [Syncfusion]
Replied On July 14, 2009 04:24 PM UTC

Here is a sample that uses multiple virtual grids to display values from a xls file in a TabControl. It avoids the issue you are seeing by putting the tabname in the Model.TableStyle.Tag property. It also adds a ScrollViewer for each GridControl so they will scroll OK. Finally, there is code in the QueryCellInfo handler that shows ways of displaying various content from formula cells in Excel. The active code shows the actual formulas, but commented code shows number values and string values.



TabbedGrids_2ab088f8.zip

Administrator [Syncfusion]
Replied On July 15, 2009 04:10 PM UTC

Hi

Thanks for the code sample - I just needed to tweak mine on a couple of lines to get the same result. One thing I did notice though was that I had to increment the used row and column count by 1 in order for sheets after the first to be properly imported, though the first sheet did not require this buffer zone.

For testing purposes the 2nd and 3rd sheets just had "testValue" in a 4x4 grid of cells starting at A1. I found that 1 row and 1 column would get truncated. Again, the +1 on the counts were not required on the 1st sheet.
Not sure if you can classify this as a bug without repro code, but thought I'd let you know what I'd experienced.


Many thanks


Paul Eden

Clay Burch [Syncfusion]
Replied On July 16, 2009 07:19 AM UTC

The code in the above sample adds the +1 on all sheets.

grdSheet.Model.RowCount = sheet.UsedRange.Rows.Count() + 1;
grdSheet.Model.ColumnCount = sheet.UsedRange.Columns.Count() + 1;


The reason for the +1 is the extra row header column and column header row that appear in the GridControl, but not in the Excel sheet. I am not sure why you did not need this for your 1st sheet though. Maybe you have cells with some blank values in the last row/column. In general, I would expect the +1 to be needed.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;