Connecting Tech Pros Worldwide Help | Site Map

DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ?

Diego TERCERO
Guest
 
Posts: n/a
#1: Nov 15 '05
Hi...
I'm working on a tool for editing text resources for a family of software
product my company produces.

These text resources are found in a SQL Server database, in a table called
"Resource" with the following structure :
Resource{[id],en,fr,es}
Yes.. these are the only languages supported actually.

A couple of rows in that table would look like this :
id | en | fr | es |
0000001 | Open |Ouvrir | Abrir |
0000002 | Close | Fermer | Cerrar |
etc...

I have a DataSet object, that I have filled with a SqlDataAdapter,
therefore, the first table of my Dataset is called "Resource" and has
exactly the same structure than the Table in the database.

I have a ListBox component that uses this DataSet as its DataSource. Its
DataMember property is the "Resource" table and its display member depends
on which is the primary display language that the user has chosen.

So the typical display of this listbox, if the user has chosen 'en' would be
:
Open
Close
.....

Then, when a user selects one of the list items, I use the selected row to
fill a DataGrid component in order to allow the user to edit all language
versions of the resource in a DataGrid.

Now here comes my problem. If I use a filtered version of this DataSet as
the DataSource of my DataGrid (for example a DataViewManager), the grid will
have exactly the same look than the table I have shown above. That doesn't
work for me, cause some resources could be very long error messages,
therefore, I would like to show each column of the table as a row in the
datagrid, something like this (assuming that I have chosen the item 0000001
Language | Value
en | Close
fr | Fermer
es | Cerrar

As for now, I have manually done this transformation by creating a table
called "ResourceItem" in the DataSource bounded to my DataGrid which I fill
by looping on the columns of the selected row. Here's a sample :

foreach(DataColumn col in drSelectedRow.Tables["Resource"].Columns){
DataRow newGridRow = dsGridDataSet.Tables["ResourceItem"].Rows.NewRow();
newGridRow["Language"] = col.ColumnName;
newGridRow["Value"] = drSelectedRow[col].ToString();
dsGridDataSet.Add(newGridRow);
}

I don't like this solution 'cause it's finally not a matter of datastructure
but a matter of display. I just would like to be able to show the columns of
my original DataSet as rows in my DataGrid. Any idea how can I achieve that
?

Thanxs,

Diego

P.S. : I'm aware of the cool ways to manage Globalization in .Net and
resource files, but this is not my question. The purpose of my tool is to
edit resource files for legacy software programmed in VB6 or in ASP 4.0. So
the edition of resources is to be done with this tool I'm working on in C#
but the edited resource files are intended to be used by other older
software.






Dmitriy Lapshin [C# / .NET MVP]
Guest
 
Posts: n/a
#2: Nov 15 '05

re: DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ?


Hi Diego,

I think as your users will be editing the resources row-by-row, you don't
need the DataGrid at all. Instead, add a layout like this:



Label: [Open [V] (kinda drop-down list)

_____________________________
English text: [_____________________________] (consider multi-line edit?)
_____________________________
French text: [_____________________________] (consider multi-line edit?)
_____________________________
Spanish text: [_____________________________] (consider multi-line edit?)

______________
| Save |
--------------


The text boxes will be data-bound to the corresponding columns of the
filtered DataView.

P.S. Hope my ASCII art won't be mangled :-)

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Diego TERCERO" <diego.tercero@freesurf.fr> wrote in message
news:3fe23e38$0$6967$7a628cd7@news.club-internet.fr...[color=blue]
> Hi...
> I'm working on a tool for editing text resources for a family of software
> product my company produces.
>
> These text resources are found in a SQL Server database, in a table called
> "Resource" with the following structure :
> Resource{[id],en,fr,es}
> Yes.. these are the only languages supported actually.
>
> A couple of rows in that table would look like this :
> id | en | fr | es |
> 0000001 | Open |Ouvrir | Abrir |
> 0000002 | Close | Fermer | Cerrar |
> etc...
>
> I have a DataSet object, that I have filled with a SqlDataAdapter,
> therefore, the first table of my Dataset is called "Resource" and has
> exactly the same structure than the Table in the database.
>
> I have a ListBox component that uses this DataSet as its DataSource. Its
> DataMember property is the "Resource" table and its display member depends
> on which is the primary display language that the user has chosen.
>
> So the typical display of this listbox, if the user has chosen 'en' would[/color]
be[color=blue]
> :
> Open
> Close
> ....
>
> Then, when a user selects one of the list items, I use the selected row to
> fill a DataGrid component in order to allow the user to edit all language
> versions of the resource in a DataGrid.
>
> Now here comes my problem. If I use a filtered version of this DataSet as
> the DataSource of my DataGrid (for example a DataViewManager), the grid[/color]
will[color=blue]
> have exactly the same look than the table I have shown above. That doesn't
> work for me, cause some resources could be very long error messages,
> therefore, I would like to show each column of the table as a row in the
> datagrid, something like this (assuming that I have chosen the item[/color]
0000001[color=blue]
> Language | Value
> en | Close
> fr | Fermer
> es | Cerrar
>
> As for now, I have manually done this transformation by creating a table
> called "ResourceItem" in the DataSource bounded to my DataGrid which I[/color]
fill[color=blue]
> by looping on the columns of the selected row. Here's a sample :
>
> foreach(DataColumn col in drSelectedRow.Tables["Resource"].Columns){
> DataRow newGridRow =[/color]
dsGridDataSet.Tables["ResourceItem"].Rows.NewRow();[color=blue]
> newGridRow["Language"] = col.ColumnName;
> newGridRow["Value"] = drSelectedRow[col].ToString();
> dsGridDataSet.Add(newGridRow);
> }
>
> I don't like this solution 'cause it's finally not a matter of[/color]
datastructure[color=blue]
> but a matter of display. I just would like to be able to show the columns[/color]
of[color=blue]
> my original DataSet as rows in my DataGrid. Any idea how can I achieve[/color]
that[color=blue]
> ?
>
> Thanxs,
>
> Diego
>
> P.S. : I'm aware of the cool ways to manage Globalization in .Net and
> resource files, but this is not my question. The purpose of my tool is to
> edit resource files for legacy software programmed in VB6 or in ASP 4.0.[/color]
So[color=blue]
> the edition of resources is to be done with this tool I'm working on in C#
> but the edited resource files are intended to be used by other older
> software.
>
>
>
>
>
>[/color]

Le Big Mac
Guest
 
Posts: n/a
#3: Nov 15 '05

re: DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ?


Hi Dimitry,
I have thought about this solution.
The problem is that I wanted to use a DataGrid because the number of
available languages is not fixed : it is supposed to be known dynamically.
That means, that my DataGrid is bounded to a DataSet that has a structure
that I don't know at design time, only at runtime (I give users the
possibility to open a specific Resource table, whose structure I don't know
yet).

So a solution would be to dynamically create labels and textboxes and bound
them to the Resources dataset after having guessed which structure this
DataSet has (remember that sometimes there might be more than French,
English or Spanish... resources).

I think that doing this results in code complication, performance overhead,
and amounts the risk of generating exceptions, this is tipically the kind of
situation for which the DataGrid is pretty wel suited.

Now... my only problem is that I need to adapt its look to my issue :
display rows as columns.
I know this is possible because I've found in Google a resource that
speciffically adresses this issue, but the link is dead !

Thanxs for your help.

Diego

"Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.com> a ecrit
dans le message de news:%23yGmi3hxDHA.1760@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi Diego,
>
> I think as your users will be editing the resources row-by-row, you don't
> need the DataGrid at all. Instead, add a layout like this:
>
>
>
> Label: [Open [V] (kinda drop-down list)
>
> _____________________________
> English text: [_____________________________] (consider multi-line edit?)
> _____________________________
> French text: [_____________________________] (consider multi-line edit?)
> _____________________________
> Spanish text: [_____________________________] (consider multi-line edit?)
>
> ______________
> | Save |
> --------------
>
>
> The text boxes will be data-bound to the corresponding columns of the
> filtered DataView.
>
> P.S. Hope my ASCII art won't be mangled :-)
>
> --
> Dmitriy Lapshin [C# / .NET MVP]
> X-Unity Test Studio
> http://x-unity.miik.com.ua/teststudio.aspx
> Bring the power of unit testing to VS .NET IDE
>
> "Diego TERCERO" <diego.tercero@freesurf.fr> wrote in message
> news:3fe23e38$0$6967$7a628cd7@news.club-internet.fr...[color=green]
> > Hi...
> > I'm working on a tool for editing text resources for a family of[/color][/color]
software[color=blue][color=green]
> > product my company produces.
> >
> > These text resources are found in a SQL Server database, in a table[/color][/color]
called[color=blue][color=green]
> > "Resource" with the following structure :
> > Resource{[id],en,fr,es}
> > Yes.. these are the only languages supported actually.
> >
> > A couple of rows in that table would look like this :
> > id | en | fr | es |
> > 0000001 | Open |Ouvrir | Abrir |
> > 0000002 | Close | Fermer | Cerrar |
> > etc...
> >
> > I have a DataSet object, that I have filled with a SqlDataAdapter,
> > therefore, the first table of my Dataset is called "Resource" and has
> > exactly the same structure than the Table in the database.
> >
> > I have a ListBox component that uses this DataSet as its DataSource. Its
> > DataMember property is the "Resource" table and its display member[/color][/color]
depends[color=blue][color=green]
> > on which is the primary display language that the user has chosen.
> >
> > So the typical display of this listbox, if the user has chosen 'en'[/color][/color]
would[color=blue]
> be[color=green]
> > :
> > Open
> > Close
> > ....
> >
> > Then, when a user selects one of the list items, I use the selected row[/color][/color]
to[color=blue][color=green]
> > fill a DataGrid component in order to allow the user to edit all[/color][/color]
language[color=blue][color=green]
> > versions of the resource in a DataGrid.
> >
> > Now here comes my problem. If I use a filtered version of this DataSet[/color][/color]
as[color=blue][color=green]
> > the DataSource of my DataGrid (for example a DataViewManager), the grid[/color]
> will[color=green]
> > have exactly the same look than the table I have shown above. That[/color][/color]
doesn't[color=blue][color=green]
> > work for me, cause some resources could be very long error messages,
> > therefore, I would like to show each column of the table as a row in the
> > datagrid, something like this (assuming that I have chosen the item[/color]
> 0000001[color=green]
> > Language | Value
> > en | Close
> > fr | Fermer
> > es | Cerrar
> >
> > As for now, I have manually done this transformation by creating a table
> > called "ResourceItem" in the DataSource bounded to my DataGrid which I[/color]
> fill[color=green]
> > by looping on the columns of the selected row. Here's a sample :
> >
> > foreach(DataColumn col in drSelectedRow.Tables["Resource"].Columns){
> > DataRow newGridRow =[/color]
> dsGridDataSet.Tables["ResourceItem"].Rows.NewRow();[color=green]
> > newGridRow["Language"] = col.ColumnName;
> > newGridRow["Value"] = drSelectedRow[col].ToString();
> > dsGridDataSet.Add(newGridRow);
> > }
> >
> > I don't like this solution 'cause it's finally not a matter of[/color]
> datastructure[color=green]
> > but a matter of display. I just would like to be able to show the[/color][/color]
columns[color=blue]
> of[color=green]
> > my original DataSet as rows in my DataGrid. Any idea how can I achieve[/color]
> that[color=green]
> > ?
> >
> > Thanxs,
> >
> > Diego
> >
> > P.S. : I'm aware of the cool ways to manage Globalization in .Net and
> > resource files, but this is not my question. The purpose of my tool is[/color][/color]
to[color=blue][color=green]
> > edit resource files for legacy software programmed in VB6 or in ASP 4.0.[/color]
> So[color=green]
> > the edition of resources is to be done with this tool I'm working on in[/color][/color]
C#[color=blue][color=green]
> > but the edited resource files are intended to be used by other older
> > software.
> >
> >
> >
> >
> >
> >[/color]
>[/color]


Dmitriy Lapshin [C# / .NET MVP]
Guest
 
Posts: n/a
#4: Nov 15 '05

re: DataGrid Component | Displaying columns of a DataSet as Rows in a DataGrid ?


Standard Windows Forms datagrid cannot display data with rows and columns
swapped. You should probably consider a 3rd party component, or indeed
transpose the data programatically - I think it's pretty viable solution for
your application.

I know I will be flamed for this, but, after all, the users of your
application don't care how perfect it's design is - what they care about is
how convenient and reliable it is.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Le Big Mac" <lebigmac@somedomain.com> wrote in message
news:3fe2df59$0$1167$636a55ce@news.free.fr...
[color=blue]
> Hi Dimitry,
> I have thought about this solution.
> The problem is that I wanted to use a DataGrid because the number of
> available languages is not fixed : it is supposed to be known dynamically.
> That means, that my DataGrid is bounded to a DataSet that has a structure
> that I don't know at design time, only at runtime (I give users the
> possibility to open a specific Resource table, whose structure I don't[/color]
know[color=blue]
> yet).
>
> So a solution would be to dynamically create labels and textboxes and[/color]
bound[color=blue]
> them to the Resources dataset after having guessed which structure this
> DataSet has (remember that sometimes there might be more than French,
> English or Spanish... resources).
>
> I think that doing this results in code complication, performance[/color]
overhead,[color=blue]
> and amounts the risk of generating exceptions, this is tipically the kind[/color]
of[color=blue]
> situation for which the DataGrid is pretty wel suited.
>
> Now... my only problem is that I need to adapt its look to my issue :
> display rows as columns.
> I know this is possible because I've found in Google a resource that
> speciffically adresses this issue, but the link is dead !
>
> Thanxs for your help.
>
> Diego
>
> "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.com> a[/color]
ecrit[color=blue]
> dans le message de news:%23yGmi3hxDHA.1760@TK2MSFTNGP10.phx.gbl...[color=green]
> > Hi Diego,
> >
> > I think as your users will be editing the resources row-by-row, you[/color][/color]
don't[color=blue][color=green]
> > need the DataGrid at all. Instead, add a layout like this:
> >
> >
> >
> > Label: [Open [V] (kinda drop-down list)
> >
> > _____________________________
> > English text: [_____________________________] (consider multi-line[/color][/color]
edit?)[color=blue][color=green]
> > _____________________________
> > French text: [_____________________________] (consider multi-line[/color][/color]
edit?)[color=blue][color=green]
> > _____________________________
> > Spanish text: [_____________________________] (consider multi-line[/color][/color]
edit?)[color=blue][color=green]
> >
> > ______________
> > | Save |
> > --------------
> >
> >
> > The text boxes will be data-bound to the corresponding columns of the
> > filtered DataView.
> >
> > P.S. Hope my ASCII art won't be mangled :-)
> >
> > --
> > Dmitriy Lapshin [C# / .NET MVP]
> > X-Unity Test Studio
> > http://x-unity.miik.com.ua/teststudio.aspx
> > Bring the power of unit testing to VS .NET IDE
> >
> > "Diego TERCERO" <diego.tercero@freesurf.fr> wrote in message
> > news:3fe23e38$0$6967$7a628cd7@news.club-internet.fr...[color=darkred]
> > > Hi...
> > > I'm working on a tool for editing text resources for a family of[/color][/color]
> software[color=green][color=darkred]
> > > product my company produces.
> > >
> > > These text resources are found in a SQL Server database, in a table[/color][/color]
> called[color=green][color=darkred]
> > > "Resource" with the following structure :
> > > Resource{[id],en,fr,es}
> > > Yes.. these are the only languages supported actually.
> > >
> > > A couple of rows in that table would look like this :
> > > id | en | fr | es |
> > > 0000001 | Open |Ouvrir | Abrir |
> > > 0000002 | Close | Fermer | Cerrar |
> > > etc...
> > >
> > > I have a DataSet object, that I have filled with a SqlDataAdapter,
> > > therefore, the first table of my Dataset is called "Resource" and has
> > > exactly the same structure than the Table in the database.
> > >
> > > I have a ListBox component that uses this DataSet as its DataSource.[/color][/color][/color]
Its[color=blue][color=green][color=darkred]
> > > DataMember property is the "Resource" table and its display member[/color][/color]
> depends[color=green][color=darkred]
> > > on which is the primary display language that the user has chosen.
> > >
> > > So the typical display of this listbox, if the user has chosen 'en'[/color][/color]
> would[color=green]
> > be[color=darkred]
> > > :
> > > Open
> > > Close
> > > ....
> > >
> > > Then, when a user selects one of the list items, I use the selected[/color][/color][/color]
row[color=blue]
> to[color=green][color=darkred]
> > > fill a DataGrid component in order to allow the user to edit all[/color][/color]
> language[color=green][color=darkred]
> > > versions of the resource in a DataGrid.
> > >
> > > Now here comes my problem. If I use a filtered version of this DataSet[/color][/color]
> as[color=green][color=darkred]
> > > the DataSource of my DataGrid (for example a DataViewManager), the[/color][/color][/color]
grid[color=blue][color=green]
> > will[color=darkred]
> > > have exactly the same look than the table I have shown above. That[/color][/color]
> doesn't[color=green][color=darkred]
> > > work for me, cause some resources could be very long error messages,
> > > therefore, I would like to show each column of the table as a row in[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > datagrid, something like this (assuming that I have chosen the item[/color]
> > 0000001[color=darkred]
> > > Language | Value
> > > en | Close
> > > fr | Fermer
> > > es | Cerrar
> > >
> > > As for now, I have manually done this transformation by creating a[/color][/color][/color]
table[color=blue][color=green][color=darkred]
> > > called "ResourceItem" in the DataSource bounded to my DataGrid which I[/color]
> > fill[color=darkred]
> > > by looping on the columns of the selected row. Here's a sample :
> > >
> > > foreach(DataColumn col in drSelectedRow.Tables["Resource"].Columns){
> > > DataRow newGridRow =[/color]
> > dsGridDataSet.Tables["ResourceItem"].Rows.NewRow();[color=darkred]
> > > newGridRow["Language"] = col.ColumnName;
> > > newGridRow["Value"] = drSelectedRow[col].ToString();
> > > dsGridDataSet.Add(newGridRow);
> > > }
> > >
> > > I don't like this solution 'cause it's finally not a matter of[/color]
> > datastructure[color=darkred]
> > > but a matter of display. I just would like to be able to show the[/color][/color]
> columns[color=green]
> > of[color=darkred]
> > > my original DataSet as rows in my DataGrid. Any idea how can I achieve[/color]
> > that[color=darkred]
> > > ?
> > >
> > > Thanxs,
> > >
> > > Diego
> > >
> > > P.S. : I'm aware of the cool ways to manage Globalization in .Net and
> > > resource files, but this is not my question. The purpose of my tool is[/color][/color]
> to[color=green][color=darkred]
> > > edit resource files for legacy software programmed in VB6 or in ASP[/color][/color][/color]
4.0.[color=blue][color=green]
> > So[color=darkred]
> > > the edition of resources is to be done with this tool I'm working on[/color][/color][/color]
in[color=blue]
> C#[color=green][color=darkred]
> > > but the edited resource files are intended to be used by other older
> > > software.
> > >
> > >
> > >
> > >
> > >
> > >[/color]
> >[/color]
>
>[/color]

Closed Thread


Similar C# / C Sharp bytes