By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

dataview sorting in manual order?

P: n/a
Is it possible to somehow sort a dataview, all on one column, but on
different variables?

That is, I have a 'Title' column in my dataview and I'd like to display
first all "Directors" (sorted), then everyone else (sorted). I've used the
'ItemBound' but can't figure out how to do this with that procedure.

Thanks in advance, any ideas are appreciated.

Jason

eg of what I'm looking for:

Name Title
===== ======
George Director
Yvonne Director
Harry Programmer
Larry Research Officer
Wilbur Secretary


Nov 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Right after you bind the dataview, do the following:

dataview.Sort = "Titles ASC, Directors ASC"

"Jason" wrote:
Is it possible to somehow sort a dataview, all on one column, but on
different variables?

That is, I have a 'Title' column in my dataview and I'd like to display
first all "Directors" (sorted), then everyone else (sorted). I've used the
'ItemBound' but can't figure out how to do this with that procedure.

Thanks in advance, any ideas are appreciated.

Jason

eg of what I'm looking for:

Name Title
===== ======
George Director
Yvonne Director
Harry Programmer
Larry Research Officer
Wilbur Secretary


Nov 18 '05 #2

P: n/a
Unfortunately, I get:

Exception Details: System.IndexOutOfRangeException: Cannot find column
Director.

Source Error:

Line 197:
Line 198: DGADResults.DataSource = dvCustom
Line 199: dvCustom.Sort = "title ASC, Director ASC"
Line 200: DGADResults.DataBind()
Line 201: End Sub
thoughts?
"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
Right after you bind the dataview, do the following:

dataview.Sort = "Titles ASC, Directors ASC"

"Jason" wrote:
Is it possible to somehow sort a dataview, all on one column, but on
different variables?

That is, I have a 'Title' column in my dataview and I'd like to display
first all "Directors" (sorted), then everyone else (sorted). I've used the 'ItemBound' but can't figure out how to do this with that procedure.

Thanks in advance, any ideas are appreciated.

Jason

eg of what I'm looking for:

Name Title
===== ======
George Director
Yvonne Director
Harry Programmer
Larry Research Officer
Wilbur Secretary


Nov 18 '05 #3

P: n/a
Jason:

You don't have a column named "Director". Change the Sort to only use
columns you do have, like Title and Name.

dataview.Sort = "Title ASC"

--
Scott
http://www.OdeToCode.com

On Wed, 1 Sep 2004 16:50:33 -0600, "Jason" <ja***@grossmans.net>
wrote:
Unfortunately, I get:

Exception Details: System.IndexOutOfRangeException: Cannot find column
Director.

Source Error:

Line 197:
Line 198: DGADResults.DataSource = dvCustom
Line 199: dvCustom.Sort = "title ASC, Director ASC"
Line 200: DGADResults.DataBind()
Line 201: End Sub
thoughts?
"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message
news:76**********************************@microso ft.com...
Right after you bind the dataview, do the following:

dataview.Sort = "Titles ASC, Directors ASC"

"Jason" wrote:
> Is it possible to somehow sort a dataview, all on one column, but on
> different variables?
>
> That is, I have a 'Title' column in my dataview and I'd like to display
> first all "Directors" (sorted), then everyone else (sorted). I've usedthe > 'ItemBound' but can't figure out how to do this with that procedure.
>
> Thanks in advance, any ideas are appreciated.
>
> Jason
>
> eg of what I'm looking for:
>
> Name Title
> ===== ======
> George Director
> Yvonne Director
> Harry Programmer
> Larry Research Officer
> Wilbur Secretary
>
>
>
>
>


Nov 18 '05 #4

P: n/a
I guess it has to be

DGADResults.DataSource = dvCustom
dvCustom.Sort = "title ASC, Name ASC"
DGADResults.DataBind()
"Jason" wrote:
Unfortunately, I get:

Exception Details: System.IndexOutOfRangeException: Cannot find column
Director.

Source Error:

Line 197:
Line 198: DGADResults.DataSource = dvCustom
Line 199: dvCustom.Sort = "title ASC, Director ASC"
Line 200: DGADResults.DataBind()
Line 201: End Sub
thoughts?
"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
Right after you bind the dataview, do the following:

dataview.Sort = "Titles ASC, Directors ASC"

"Jason" wrote:
Is it possible to somehow sort a dataview, all on one column, but on
different variables?

That is, I have a 'Title' column in my dataview and I'd like to display
first all "Directors" (sorted), then everyone else (sorted). I've used the 'ItemBound' but can't figure out how to do this with that procedure.

Thanks in advance, any ideas are appreciated.

Jason

eg of what I'm looking for:

Name Title
===== ======
George Director
Yvonne Director
Harry Programmer
Larry Research Officer
Wilbur Secretary



Nov 18 '05 #5

P: n/a
First off, thanks to everyone who's responded, I think we're almost there:

Alright, so I've sorted dataviews before by a column name like this without
a problem. What I'm trying to get however is a sorted list of all rows
whose column 'title' has a value of "Director" -THEN- list the rest of the
rows in normal sorted order.

That is, just as in my example below, although Yvonne and George should not
be at the top of the list because their names fall alphabetically below
'Barry', because they have a title='Director' value, I would like them to be
on the top of the list first. Following all of these Directors, Barry,
Larry, and Wilbur are sorted normally.

Name Title
===== ======
George Director
Yvonne Director
Barry Programmer
Larry Research Officer
Wilbur Secretary

dataview.Sort = "Title ASC" won't cut it, nor would dvCustom.Sort = "title
ASC, Name ASC" because my data could contain a title='Associate something'
that would take the top spot instead of any "Director".

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:uh********************************@4ax.com...
Jason:

You don't have a column named "Director". Change the Sort to only use
columns you do have, like Title and Name.

dataview.Sort = "Title ASC"

--
Scott
http://www.OdeToCode.com

On Wed, 1 Sep 2004 16:50:33 -0600, "Jason" <ja***@grossmans.net>
wrote:
Unfortunately, I get:

Exception Details: System.IndexOutOfRangeException: Cannot find column
Director.

Source Error:

Line 197:
Line 198: DGADResults.DataSource = dvCustom
Line 199: dvCustom.Sort = "title ASC, Director ASC"
Line 200: DGADResults.DataBind()
Line 201: End Sub
thoughts?
"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message
news:76**********************************@microso ft.com...
Right after you bind the dataview, do the following:

dataview.Sort = "Titles ASC, Directors ASC"

"Jason" wrote:

> Is it possible to somehow sort a dataview, all on one column, but on
> different variables?
>
> That is, I have a 'Title' column in my dataview and I'd like to display > first all "Directors" (sorted), then everyone else (sorted). I've
usedthe
> 'ItemBound' but can't figure out how to do this with that procedure.
>
> Thanks in advance, any ideas are appreciated.
>
> Jason
>
> eg of what I'm looking for:
>
> Name Title
> ===== ======
> George Director
> Yvonne Director
> Harry Programmer
> Larry Research Officer
> Wilbur Secretary
>
>
>
>
>

Nov 18 '05 #6

P: n/a
Ah, thats a bit tricker. There is no built in way to do this easily
but here is something to try...

Add an additional column to the underlying DataTable. When the Title
is Director, set the value of this column to 1, when the Title is not
a director, set the value to 2. Then you could use a Sort expression
like:

dv.Sort = "SortColumn ASC, Name ASC";

The additional column could be a computed column. Add the column
programatically:

dataTable.Columns.Add("SortColumn", typeof(int), expr);

Where expr is an expression like:

"IIF(Title='Director', 1, 2)"
HTH,

--
Scott
http://www.OdeToCode.com

On Thu, 2 Sep 2004 08:04:51 -0600, "Jason" <ja***@grossmans.net>
wrote:
First off, thanks to everyone who's responded, I think we're almost there:

Alright, so I've sorted dataviews before by a column name like this without
a problem. What I'm trying to get however is a sorted list of all rows
whose column 'title' has a value of "Director" -THEN- list the rest of the
rows in normal sorted order.

That is, just as in my example below, although Yvonne and George should not
be at the top of the list because their names fall alphabetically below
'Barry', because they have a title='Director' value, I would like them to be
on the top of the list first. Following all of these Directors, Barry,
Larry, and Wilbur are sorted normally.

Name Title
===== ======
George Director
Yvonne Director
Barry Programmer
Larry Research Officer
Wilbur Secretary

dataview.Sort = "Title ASC" won't cut it, nor would dvCustom.Sort = "title
ASC, Name ASC" because my data could contain a title='Associate something'
that would take the top spot instead of any "Director".

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:uh********************************@4ax.com.. .
Jason:

You don't have a column named "Director". Change the Sort to only use
columns you do have, like Title and Name.

dataview.Sort = "Title ASC"

--
Scott
http://www.OdeToCode.com

On Wed, 1 Sep 2004 16:50:33 -0600, "Jason" <ja***@grossmans.net>
wrote:
>Unfortunately, I get:
>
>Exception Details: System.IndexOutOfRangeException: Cannot find column
>Director.
>
>Source Error:
>
>Line 197:
>Line 198: DGADResults.DataSource = dvCustom
>Line 199: dvCustom.Sort = "title ASC, Director ASC"
>Line 200: DGADResults.DataBind()
>Line 201: End Sub
>
>
>thoughts?
>
>
>"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message
>news:76**********************************@microso ft.com...
>> Right after you bind the dataview, do the following:
>>
>> dataview.Sort = "Titles ASC, Directors ASC"
>>
>> "Jason" wrote:
>>
>> > Is it possible to somehow sort a dataview, all on one column, but on
>> > different variables?
>> >
>> > That is, I have a 'Title' column in my dataview and I'd like todisplay >> > first all "Directors" (sorted), then everyone else (sorted). I'veused >the
>> > 'ItemBound' but can't figure out how to do this with that procedure.
>> >
>> > Thanks in advance, any ideas are appreciated.
>> >
>> > Jason
>> >
>> > eg of what I'm looking for:
>> >
>> > Name Title
>> > ===== ======
>> > George Director
>> > Yvonne Director
>> > Harry Programmer
>> > Larry Research Officer
>> > Wilbur Secretary
>> >
>> >
>> >
>> >
>> >
>


Nov 18 '05 #7

P: n/a
Good idea, I'll give that a whirl and it should suit my needs just fine.

Thanks alot!

Jay

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:ai********************************@4ax.com...
Ah, thats a bit tricker. There is no built in way to do this easily
but here is something to try...

Add an additional column to the underlying DataTable. When the Title
is Director, set the value of this column to 1, when the Title is not
a director, set the value to 2. Then you could use a Sort expression
like:

dv.Sort = "SortColumn ASC, Name ASC";

The additional column could be a computed column. Add the column
programatically:

dataTable.Columns.Add("SortColumn", typeof(int), expr);

Where expr is an expression like:

"IIF(Title='Director', 1, 2)"
HTH,

--
Scott
http://www.OdeToCode.com

On Thu, 2 Sep 2004 08:04:51 -0600, "Jason" <ja***@grossmans.net>
wrote:
First off, thanks to everyone who's responded, I think we're almost there:
Alright, so I've sorted dataviews before by a column name like this withouta problem. What I'm trying to get however is a sorted list of all rows
whose column 'title' has a value of "Director" -THEN- list the rest of therows in normal sorted order.

That is, just as in my example below, although Yvonne and George should notbe at the top of the list because their names fall alphabetically below
'Barry', because they have a title='Director' value, I would like them to beon the top of the list first. Following all of these Directors, Barry,
Larry, and Wilbur are sorted normally.

Name Title
===== ======
George Director
Yvonne Director
Barry Programmer
Larry Research Officer
Wilbur Secretary

dataview.Sort = "Title ASC" won't cut it, nor would dvCustom.Sort = "titleASC, Name ASC" because my data could contain a title='Associate something'that would take the top spot instead of any "Director".

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:uh********************************@4ax.com.. .
Jason:

You don't have a column named "Director". Change the Sort to only use
columns you do have, like Title and Name.

dataview.Sort = "Title ASC"

--
Scott
http://www.OdeToCode.com

On Wed, 1 Sep 2004 16:50:33 -0600, "Jason" <ja***@grossmans.net>
wrote:

>Unfortunately, I get:
>
>Exception Details: System.IndexOutOfRangeException: Cannot find column
>Director.
>
>Source Error:
>
>Line 197:
>Line 198: DGADResults.DataSource = dvCustom
>Line 199: dvCustom.Sort = "title ASC, Director ASC"
>Line 200: DGADResults.DataBind()
>Line 201: End Sub
>
>
>thoughts?
>
>
>"Matt Hamilton" <Ma**********@discussions.microsoft.com> wrote in message >news:76**********************************@microso ft.com...
>> Right after you bind the dataview, do the following:
>>
>> dataview.Sort = "Titles ASC, Directors ASC"
>>
>> "Jason" wrote:
>>
>> > Is it possible to somehow sort a dataview, all on one column, but on >> > different variables?
>> >
>> > That is, I have a 'Title' column in my dataview and I'd like to

display
>> > first all "Directors" (sorted), then everyone else (sorted). I've

used
>the
>> > 'ItemBound' but can't figure out how to do this with that procedure. >> >
>> > Thanks in advance, any ideas are appreciated.
>> >
>> > Jason
>> >
>> > eg of what I'm looking for:
>> >
>> > Name Title
>> > ===== ======
>> > George Director
>> > Yvonne Director
>> > Harry Programmer
>> > Larry Research Officer
>> > Wilbur Secretary
>> >
>> >
>> >
>> >
>> >
>

Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.