[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 13216
  • Last Modified:

Infragistics UltraGrid

I need to populate the Infragistics UltraGrid. I am using the datasset. The stored procedure returns 2 columns month, year.For month it returns the 1,2..........or 12.I can't change the storedprocedure
I am thinking of adding a column to the dataset which displays month and year. It shouldbe like this.January,2008. It has to combine the month and year columns and month number substituted with month name.
Pls let me know the possible ways of doing this.
Thank You
0
KavyaV
Asked:
KavyaV
  • 2
1 Solution
 
ZeonFlashCommented:
Instead of adding a column to the dataset, you can just add an unbound column to hold the combined month/year, and populate it in the InitializeRow event.  I used a VB.NET->C# translator to get the code below, so let me know if it doesn't work:
    private void UltraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) {
        UltraGrid1.DisplayLayout.Bands(0).Columns.Add("CombinedDate");
        UltraGrid1.DisplayLayout.Bands(0).Columns["CombinedDate"].DataType = typeof(DateTime);
        UltraGrid1.DisplayLayout.Bands(0).Columns["CombinedDate"].Format = "MMMM yyyy";
        UltraGrid1.DisplayLayout.Bands(0).Columns["Month"].Hidden = true;
        UltraGrid1.DisplayLayout.Bands(0).Columns["Year"].Hidden = true;
    }
    
    private void UltraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) {
        e.Row.Cells["CombinedDate"].Value = DateTime.Parse((e.Row.Cells["Month"].Value + ("/01/" + e.Row.Cells["Year"].Value)));
    }

Open in new window

0
 
KavyaVAuthor Commented:
ZeonFlash,
I tried what you suggested.But it's not working. the ultragrid has 3 more columns other than the combineddate.The data for those 3 columns are displayed.I added 3 columns to the ultragrid by clicking the start designing the gridview. I used manually define a schema  and band&column settings. I added 3 columns ID,Volumechanged,VolumeTotal like this and hide the month and year columns.
Then in the code I did like this:
private void  UltraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            UltraGrid1.DisplayLayout.Bands[0].Columns.Add("CombinedDate");
            UltraGrid1.DisplayLayout.Bands[0].Columns["CombinedDate"].DataType = typeof(DateTime);
            UltraGrid1.DisplayLayout.Bands[0].Columns["CombinedDate"].Format = "MMMM yyyy";
          }
        private void  UltraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
        {
            e.Row.Cells["CombinedDate"].Value = DateTime.Parse((e.Row.Cells["Month"].Value + ("/01/" + e.Row.Cells["Year"].Value)));
        }
I retrieved the dataset and assigned to grid.
UltraGrid1.Datasource= ds;
UltraGrid1.Datamember = "volume";
The 3 columns(id,volume changed,volume total) are populated with the data. The CombinedDate column is not added to the UltraGrid.
2)In the 2nd case I added one unbound column CombinedDate while manually designing the gridview
and use the UltraGrid1_InitializeRow method.In this case the row is added to the grid and is not populated with the data.

Is there any mistakes in the way I did. Pls let me know how to populate the CombinedDate column.

Thank You.




0
 
ZeonFlashCommented:
Did you add the InitializeRow event handler to the InitializeComponent routine?
private void InitializeComponent()
{
	Infragistics.Win.UltraWinGrid.UltraGridBand ultraGridBand1 = new Infragistics.Win.UltraWinGrid.UltraGridBand("Band 0", -1);
.
.
.
	this.ultraGrid1.TabIndex = 0;
	this.ultraGrid1.Text = "ultraGrid1";
	this.ultraGrid1.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.ultraGrid1_InitializeLayout);
	this.ultraGrid1.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(ultraGrid1_InitializeRow);  //Add this line
.
.
.

Open in new window

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now