Re: DataGrid column formatting to display Time values
From: Steve Willcock (steve_at_N-O-S-P-A-Mwillcockconsulting.com)
Date: 08/11/04
- Next message: John Dann: "DateTime problems"
- Previous message: DraguVaso: "Unique Identifier in DataGrid remains Null..."
- In reply to: elixxir: "Re: DataGrid column formatting to display Time values"
- Next in thread: Paul Marinceu: "Re: DataGrid column formatting to display Time values"
- Reply: Paul Marinceu: "Re: DataGrid column formatting to display Time values"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 11 Aug 2004 12:27:35 +0100
You can't bind to a datarelation but you can bind to the child table of the
datarelation by specifying the correct mapping name for that child table
For the MappingName you only need to specify the TableName, not the full
name, so:
this.dataGridTableStyle2.MappingName =
"GS_Phases.GS_PhasesExams.ExamsExamSittings";
would become:
this.dataGridTableStyle2.MappingName = "ExamsExamSittings";
that's how it generally works.
Steve
"elixxir" <elixxir@ucc.asn.au> wrote in message
news:cf7t4e$b6l@odak26.prod.google.com...
> Hmm, yes, I don't think this is what I'm after...
> Maybe this calls for some code to be shown ;)
>
> So, here's basically some code made from the designer and edited to
> suit what I want...except it doesn't work. (I hope the formatting will
> not be abhorrently bad)
>
> //
> // dataGrid1
> //
> this.dataGrid1.DataMember = "";
> this.dataGrid1.DataSource = this.dataSet11;
> this.dataGrid1.HeaderForeColor =
> System.Drawing.SystemColors.ControlText;
> this.dataGrid1.Location = new System.Drawing.Point(8, 192);
> this.dataGrid1.Name = "dataGrid1";
> this.dataGrid1.Size = new System.Drawing.Size(544, 216);
> this.dataGrid1.TabIndex = 9;
> this.dataGrid1.TableStyles.AddRange(new
> System.Windows.Forms.DataGridTableStyle[] {
> this.dataGridTableStyle2});
> this.dataGrid1.Navigate += new
> System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
> //
> // dataGridTableStyle2
> //
> this.dataGridTableStyle2.DataGrid = this.dataGrid1;
> this.dataGridTableStyle2.GridColumnStyles.AddRange(new
> System.Windows.Forms.DataGridColumnStyle[] {
> this.dataGridTextBoxColumn2});
> this.dataGridTableStyle2.HeaderForeColor =
> System.Drawing.SystemColors.ControlText;
> this.dataGridTableStyle2.MappingName =
> "GS_Phases.GS_PhasesExams.ExamsExamSittings";
> //
> // dataGridTextBoxColumn2
> //
> this.dataGridTextBoxColumn2.Format = "";
> this.dataGridTextBoxColumn2.FormatInfo = null;
> this.dataGridTextBoxColumn2.MappingName = "ScheduledStartTime";
> this.dataGridTextBoxColumn2.Width = 75;
>
> Notice that the TableStyle mapping is a DataRelation which is composed
> of the following tables: GS_Phases, Exams and ExamSittings.
> I want to show a column of "ScheduledStartTime" (which is a field of
> ExamSittings) and is a Time only field.
>
> ie. when the user navigates through the various exams it'll show a
> table of exam sittings that has this information specific for that
> exam. Thus, master/detail.
>
> Now, when I run the app, all I get in the grid is a single row header
> with a + sign indicating child tables (ie. a typical master detail
> relationship), instead of a data column (of Time values, in this
> instance) as I specified.
>
> I hope this makes it clearer. So am I able to bind to a DataRelation
> somehow or not? If not, what can I do to get the desired effect?
> Thanks for your help :)
> Paul
>
> Steve Will*** wrote:
> > Unless I'm getting hold of the wrong end of the stick here, I think
> what you
> > need to do is to specify multiple TableStyles and set the MappingName
> of
> > each to match the relevant table name - i.e. one table style for the
> master
> > table and one for the detail table - this works for me on Windows
> forms
> > datagrids with master/detail realtionships to allow table specific
> > formatting.
> >
> > --
> > Steve Will***, MCSD
> > http://www.willcockconsulting.com/
> >
> >
> > "elixxir" <elixxir@ucc.asn.au> wrote in message
> > news:cf7f7p$eov@odbk17.prod.google.com...
> > > Greetings,
> > >
> > > I'd like to format a column of a DataGrid to display only the Time
> > > value instead of DateTime (ie. the format would be {0:t})
> > >
> > > The problem is that the table that the DataGrid is bound to is
> actually
> > > part of a master/detail relationship and it appears that you can't
> use
> > > TableStyles with a DataRelation.
> > >
> > > Does anyone know of a way I can get to format my columns?
> > > I'd be grateful for any hints.
> > >
> > > Paul
> > >
>
- Next message: John Dann: "DateTime problems"
- Previous message: DraguVaso: "Unique Identifier in DataGrid remains Null..."
- In reply to: elixxir: "Re: DataGrid column formatting to display Time values"
- Next in thread: Paul Marinceu: "Re: DataGrid column formatting to display Time values"
- Reply: Paul Marinceu: "Re: DataGrid column formatting to display Time values"
- Messages sorted by: [ date ] [ thread ]