|
Ok, then the second solution is best
Oh, and you don't need to do a ToList() if you're going that route. Linq results are all IEnumerable.
|
|
|
|
|
Using generics, as Ian has suggested, doesn't preclude you from doing that. You would just need to create the class/struct for each query, which from a architectural perspective isn't a bad idea. However, if you have many different queries that are possible then perhaps you need to improve your design, one size fits all implementation are very difficult to maintain.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
One more thing,
lets say I store "result" in session variable like this
public void BindGridData<t>(IEnumerable<t> result)
{
Session["result"] = result;
gridView.DataSource = result;
gridView.DataBind();
}
and then I want to call this function within another event, how do I call it? how do I cast Session["result"]?
Thanks
|
|
|
|
|
First of all don't store it in session state. Remember this is the result of your query, not the query itself, and could be very large.
It's also quite clear how to cast it. It is being passed into your method as an IEnumerable, guess what it should be cast as?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
IEnumerable<T> requires a type but IEnumerable does not.
I know the language. I've read a book. - _Madmatt
modified on Tuesday, August 31, 2010 12:12 PM
|
|
|
|
|
|
Sorry, the brackets didn't render. Fix it
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi all, I'm hoping someone could shed some light here please.
I have a ToolStripPanel on my form with a few ToolStrip s which in turn each have a few ToolStripButton s.
I wrote an event handler for the MouseEnter and MouseLeave events of all of these buttons so that I can change the image depending on whether the mouse is over the button or not. Basically, I have an animated gif which I'm showing when the mouse is over the button and a static image when it's not.
It works but it has a little glitch. Every time the image of a button changes, the size of the button changes very briefly. This means that, for a split second, the relevant ToolStrip is resized which has the effect of all the ToolStrips to the right of it being moved left. Like I say, it's only for a split second before everything is restored again (once the button has its new image) but it makes for a very unpleasant visual effect.
Any ideas?
|
|
|
|
|
Hi,
Could you post the code you're using to change the images on your buttons ? This way we would have a better idea on how you handle the stuff.
|
|
|
|
|
Sure, I have two functions:
private void toolStripButton_MouseEnter(object sender, EventArgs e)
{
switch ((sender as ToolStripItem).Name)
{
case "toolStripButton_ViewUser": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_anim_User; break;
case "toolStripButton_NewUser": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_anim_UserAdd; break;
case "toolStripButton_ViewItems": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_anim_Item; break;
case "toolStripButton_NewItems": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_anim_ItemAdd; break;
... etc.
}
}
private void toolStripButton_MouseLeave(object sender, EventArgs e)
{
switch ((sender as ToolStripItem).Name)
{
case "toolStripButton_ViewUser": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_User; break;
case "toolStripButton_NewUser": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_UserAdd; break;
case "toolStripButton_ViewItems": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_Item; break;
case "toolStripButton_NewItems": (sender as ToolStripButton).Image = Properties.Resources.BtnIcon_ItemAdd; break;
... etc.
}
}
The MouseEnter and MouseLeave events of all the buttons are handled by these two functions.
|
|
|
|
|
You can try to encapsulate switch statements between this.SuspendLayout() and this.ResumeLayout() , in order to stop rendering your form while you're changing your images.
You can also try to set the ImageScaling property of your ToolStripButtons to None ; but only if all your images have the same size, and you have set the ImageScalingSize property of your ToolStrip to the actual size of your images.
I don't have VS installed on this machine, so I was not able to test for these solutions. I hope it will help you anyway.
|
|
|
|
|
Thanks a mil. I had considered the ImageScaling option but that wouldn't work because the images are in fact bigger than the buttons and have to be scaled. The SuspendLayout() and ResumeLayout() suggestion worked like a charm though, thanks for that.
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi,
I'm using Tab Control in my application, where the text fore color is black and backcolor is white. But I would like to have fore color as white and backcolor as black. If I change "DrawMode" property to OwnerDrawFixed, I'm able to change the style. But its not showing the changed styles in XP machine. Its working in Vista machine.
Please suggest me other way to have text color as white and backcolor as black.
Thanks in advance.
|
|
|
|
|
Hi,
ForeColor and BackColor are properties of TabPages, not of TabControl itself.
Try to reset the value of TabControl.DrawMode to Normal , and set the BackColor and ForeColor properties on the TabPages.
Regards.
|
|
|
|
|
Thanks for your reply. I reset the value of TabControl.DrawMode to Normal and set the BackColor and ForeColor properties on the TabPages.
<pre>const string DEFAULT_TAB_NAME = "Default";
tabCtrl1.TabPages.Add(DEFAULT_TAB_NAME, DEFAULT_TAB_NAME);
tabCtrl1.TabPages[DEFAULT_TAB_NAME].Controls.Add(dataGridView1);
tabCtrl1.TabPages[DEFAULT_TAB_NAME].ForeColor = Color.White;
tabCtrl1.TabPages[DEFAULT_TAB_NAME].BackColor = Color.Black;</pre>
But the tabname, "Default", characters are not appearing in white color and back color not in black color. Had I followed you?
|
|
|
|
|
Hi,
I would rather do this way :
const string DEFAULT_TAB_NAME = "Default";
TabPage tp = new TabPage(DEFAULT_TAB_NAME);
tp.BackColor = Color.Black;
tp.ForeColor = Color.White;
tp.Controls.Add(dataGridView1);
tabCtrl1.TabPages.Add(tp);
I tried to change ForeColor and BackColor properties, in the designer and also programmatically, and all's working like a charm. So I guess your problem isn't in the small piece of code you provided.
|
|
|
|
|
Sorry, may be my question is not clear. The above Tabpage Back and Fore colors are belongs to the text inside the tabpage. But I would like to change the font of "Default" letters(i.e, tab header name), not the text inside the tabpage. "Default" letters should be in white color and the tab header's back area should be in Black color.
Hope the below picture gives clear idea. If not please send me your mail id, so that I'll send you the screenshot as attachment.
|--------|--> Tab header with name "Default"
|Default |
|-----------------------------------------------------------|
| |
| |
| |
| text inside the tabpage |
| |
| |
| |
| |
|-----------------------------------------------------------|
|
|
|
|
|
Hi everybody,
I want someone help me in my problem!
I made an application in C#, this application has database connection to SQL Server database (LINQ), When I want to deploy the application (make the setup) I added the SQL SERVER EXPRESS as a prerequisite to my application in order to install the SQL server in the client PC, but I had to attach the database file to SQL server manually using SQL Server Management Studio (SSMS) so I also had to install this program in the client PC.
What I want to do is to make the setup attach the database file during the setup process to SQL Server automatically without SSMS, but how? this is my problem..
Can anybody help please!
Thanks in advance!
|
|
|
|
|
Write SQL scripts like:
create database Versioncontrol
ON
( FILENAME = N'C:\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Data\Versioncontrol.mdf' ),
( FILENAME = N'C:\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Logs\Versioncontrol_log.ldf' )
for attach
go
exit
exec sp_detach_db versioncontrol
go
exit
And execute them with: sqlcmd -S localhost\sqlexpress -i attach.sql
|
|
|
|
|
Mr.PIEBALDconsult thank you for replying,
I want to attach the database from C# not from SQL server itself !
Thanks again.
|
|
|
|
|
Then execute those statements via ADO.net
Also note that I modified my response -- see if SQLCMD will do what you want.
|
|
|
|
|
I tried to excute other statments via ADO.net which is:
EXEC sp_attach_single_file_db @dbname = N'{'databasename'}' , @physname = N'{'path'}'
but an exception is occured
|
|
|
|
|
Don't you think including the exception would be helpful
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The Exception is:
DBAttachException: Cannot create file 'Database (LDF) Path' because it already exists. Change the file path or the file name, and retry the operation.
Could not open new database 'Database name'. CREATE DATABASE is aborted.
File activation failure. The physical file name "Path of my project of .Net" may be incorrect.
I hope that to be helpful !!
|
|
|
|