|
I need to create an application where a user can select some records from a DataGridView and create a Crystal Report based on those records. I basically created most of the necessary functionality using the DataGridView.SelectedRows property to get the selected rows and then importing those rows into a data table that I use to create the report, like so:
foreach(DataGridViewRow r in this.gridView_Hydro_Results.SelectedRows)
{
int selectIndex = r.Index;
row = resultsTable.Rows[selectIndex];
dtSelectedRecords.ImportRow(row);
}
Unfortunately, when I create the report, the records are not in the order of selection. Instead, the records are in the reverse order. It seems like the rows are getting added in a last in, first out order. While that may be easy to counter, my customers actually probably don't care what order the y select the records in, but want the report ordered according to some field in the database, like time or date. I suppose I could build a method to sort the Data Table (or the collection gridview rows) after I create it, but I was wondering if there is a more elegant solution.
In the same vein, is it possible to use a generic list collection in a SQL statement. I was thinking of adding the value of the primary key for each selected row to a List<> object and then using a SELECT * FROM Table WHERE KEY IN (List<>), but am not sure if that will work.
Anyway, any advice would be appreciated. Thanks.
|
|
|
|
|
Have you tried
dtSelectedRecords.Rows.Add(row)
instead? I've always gone this route, and not sure about how ImportRow behaves when inserting rows.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Thanks for the advice.
I actually did try the dtSelectedRecords.Add(row) command first, but kept getting the error that the row already belongs to another table. I didn't want to delete the row from the original table (because the original table is the one that's bound to the grid view), so I had to find some other method that imports a copy of the rows. ImportRow fits that need and it seems to simply insert the records into the table at the last position in the table. What seems to have caused the trouble is the way the rows are added to the DataGridViewRowCollection.SelectedRows collection. I think the rows are added in a last in-first out structure.
What I wound up doing-something that works for now-is import all the rows into the datatable that I need in there and then sort the datatable using the DataTable.Select function to assign the sorting criteria. I import the rows from the DataRow [] into a target table from which I create the report. It's a bit more convoluted than I want and it might not be the most efficient method, especially if the user is selecting quite a few records, but it seems to do the job.
|
|
|
|
|
Hi All,
i have a list view with two column header , one is for ItemName and second for ItemDescription , now i have to implement a search in the list view ,
and i have to make my scrollbar to be at the correct item and i have to make the selected text colored .
Can anyone has any idea how to do it , please?
Praveen Sharma
|
|
|
|
|
foreach (ListViewItem lvi in listView1.Items) {
if (lvi.IsTheOneIWant) {
lvi.ForeColor = Color.Red;
}
}
If you need help with determining if any given item is the one you're looking for, you'll need to be more specific. I personally like to put the object I'm representing in the ListViewItem 's Tag property so I can pull it out and inspect it. Gives you a lot more options when doing something like this.
|
|
|
|
|
hi ,
what is IsTheOneIWant in the code it's not listviewItem property
Praveen Sharma
|
|
|
|
|
Umm, that's where you need to determine if that's the item you're interested in. I thought that was pretty clear.
|
|
|
|
|
Adding to the previous reply, once you find your item, be sure to call its EnsureVisible method (in ListViewItem ). That will scroll the list view to show that item.
|
|
|
|
|
thanx for response ,
actually i want to search a particular text in the list view like if there is text "Cancel The Item" and i want to search search item then i want to make red only Item not the whole , it's like the search we have in wordpad or notepad .
Praveen Sharma
|
|
|
|
|
You mean only the word and not the full row? That's imposible with the built-in functionality. The most you can do is set all the text in one column to a different color, but not one word within a column.
You need to draw the text yourself (which can be some work). If you are interested, look into list view custom draw.
|
|
|
|
|
can someone explane how to create cookie and which file or class to put it?
thank you
|
|
|
|
|
daku1 wrote: can someone explane how to create cookie and which file or class to put it?
thank you
Did you try to google "c# cookie"?
In case you never heard of the google.
Webster's New Millennium Dictionary of English
Main Entry: google
Part of Speech: verb
Definition: to search for information about a specific person through the Google search engine
Example: She googled her high school boyfriends.
Etymology: trademark Google
Usage: googling n
|
|
|
|
|
Let's see. 2 sticks butter (softened), flour, baking soda, a couple eggs, pinch of salt, sugar, brown suger, a bit of vanilla extract, chocolate chips...
Seriously, your question is a bit vague. Is this an ASP.NET application? Are you trying to set a cookie on the client? Or, are you trying to create your own cookie in a Windows Forms app and sending that to a web server?
|
|
|
|
|
This[^] article may be a good place to start.
/ravi
|
|
|
|
|
yes, this is a ASP.NET and try to create a cookie on the project and it is on live within two weeks. thank you for ur answer cokkie wil be cookie to client.
thank you
|
|
|
|
|
The answer you seek is here[^].
|
|
|
|
|
Dave Kreskowiak wrote: Let's see. 2 sticks butter (softened), flour, baking soda, a couple eggs, pinch of salt, sugar, brown suger, a bit of vanilla extract, chocolate chips...
[homer simpson] mmmmmmm, cooooooookies [/homer simpson]
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
can any one suggest me gud interview questions list with answers?
|
|
|
|
|
Q: Tell me about yourself.
A: I have issues going to
Google to look stuff up.
Hogan
|
|
|
|
|
Q) What is the answer to the ultimate question of life, the universe, and everything?
A) 42
|
|
|
|
|
Q: Please explain recursion?
A: I would explain it recursively if I could explain it recursively.
|
|
|
|
|
I have never received the same set of questions at any interview I was at. However, there are some standard ones that you are likely to get such as: How are you? How was your journey? and so on.
The interview process my company uses includes a technical test where we ask you to write some software. You get given a PC with Visual Studio and some common tools on it and a specification. You have two hours - we don't expect you to complete everything, but what we are looking for is how you coped with the problem, how you structured your code, and so on. It is an "open book" test and you have access to the internet so you can use what ever resources are there.
We have found it helps eliminate those that are incapable of writing software or have exagerated their experience with the technology.
Because that test is quite intense we are considering adding a quick eliminator in the intial interview along the lines of the Buzz-Fizz problem described in Hanselminutes a few months ago.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Colin Angus Mackay wrote: You get given a PC with Visual Studio and some common tools on it and a specification.
Do they get access to Google?
|
|
|
|
|
dino2094 wrote: Do they get access to Google?
Yes. 'It is an "open book" test and you have access to the internet so you can use what ever resources are there.'
Although, I should clarify that my company uses WebSense so it won't allow access to bebo, porn or BBC News.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Colin Angus Mackay wrote: porn or BBC News
Similar sites, huh?
|
|
|
|