|
So I simply designate the cell by iterating over the rows and then designating the column like this dataGrid[rowNum][2]?
That simple?
I'm using a dataset.
Thanks,
Paul
(I've got to go now...be back later tonight.)
|
|
|
|
|
Actually, I messed the syntax up. You can get the value of a cell with:
dataGrid[rowNum, colNum]
I agree with the other post about using the dataset instead of the grid...but if you have to, you can use the grid. Keep in mind that if you use the datagrid instead of the dataset, you will have to find a way of counting the rows. This is why I used the try/catch block of stopping the loop in my example. I'm sure there are better ways...I'm just too lazy tonight to look anything up. Also, if you use the datagrid, you may have to check the values you get from the cells to make sure they are usable. If the grid is editable, you'll (almost) always have that extra row at the bottom that will have nothing, but you'll still be able to return the value from those cells.
Good luck!
- D
|
|
|
|
|
I have a C# application. This C# application also has file types associated with it (in my case, the extenion is .drb). I want to have a DIFFERENT icon compiled within my .exe that these file extensions use, however, I cannot figure out HOW to add additional icons to be compiled within my application for use by these extensions?
Am I making sense?
|
|
|
|
|
Add an icon file to your project, select the file in Solution Explorer and now in the Properties pane change the Compile property to "Embedded Resource".
After that follow standard procedure for adding file associations/icons.
|
|
|
|
|
That won't work. Embedded Resources != Win32 resources. The icons have to be accessible to Win32. Embedded resources are not.
See my reply to the poster if you want to know more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The other reply wouldn't work. Embedded resources are stored differently than Win32 resources (in C/C++, these would be referenced in the .rc file).
There are many ways you can do this. You can use the command-line compiler (csc.exe) and specify the /win32res: switch along with the path to a .res file that contains your win32 resources. In Visual Studio 2005, you will be able to specify this in the environment, which wasn't available in Visual Studio .NET 2002 and 2003.
You can also - after compiling - open the executable (.EXE or .DLL) in Visual Studio. That will show you your resource section. You can import icons and other resources types into the PE/COFF executable (the executable format on Windows).
If you sign your assemblies (and there's no reason not to - it's easy), you should resign them to make sure the hash is correct (shouldn't be a problem, but follow along anyway). Use sn.exe -R MyApp.exe KeyPair.snk, where MyApp.exe is the assembly to be signed (of course) and KeyPair.snk is the path to the key pair you used to sign the assembly in the first place. Usually it's a good idea to enable delayed signing (using the AssemblyDelaySignAttribute ) and sign it later anyway, and if you use Authenticode to sign the assembly (the PE/COFF executable, actually) then you'll definitely need to resign it after modifying it (or just don't sign it before modifying it anyway).
Again, Visual Studio 2005 will include this functionality into the IDE, which will be nice.
Alternatively, you might consider just using a native resource-only DLL with the icons you want. Create a new (unmanaged) C or C++ DLL project, add your resources (icons, bitmaps, AVIs, etc.), compile and distribute. The only problem with this approach is that Fusion (the assembly binder which can work seemlessly over the Internet) won't grab it - it only works with .NET assemblies. With installation deployments or (presumably) ClickOnce - a new touchless deployment in .NET 2.0 - this won't be a problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I want to export a report created with Crystal Reports 9 to Excel format with this condition :
I want to split the exported file into 5 files. First file for page 1 - 10, second for page 11 - 20, and so on.
What i want to know is, how can i set the number of pages exported without user interaction (by clicking export button in crystalreportviewer)?
Thanks for the help.
|
|
|
|
|
I'm thinking of writing a game in C# that have a "searching for
opponents" feature, like the internet checker included in Windows XP.
What do I need to do that? Since I'm directing searching for an opponent on the internet, so I don't think I need to have a server, do I?
Okay, but how?
|
|
|
|
|
you *could* be cheap and use the IRC protocol to make the clients go to a secluded room on a popular server, and from that point inside the room, communicate using a proprietary protocol. However, I don't think the admins of that server would smile down too kindly on you.
|
|
|
|
|
In other words, yes, you need your own server to do this. How can you search the Internet for opponenets when there are some 4 BILLION addresses to look at? You need to have some central place that each game can register itself at so you can easily contact other players. That's how all the off-the-shelf games do it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Okay, my idea is very similar to an instant messenger -- Do I
need a server for the instant messenger to work? So, if I do need
it, how do I do that? What technology should I use? SQL server?
or IRC protocol? but how to enable it?
Sorry for my stupid question........
Thanks
|
|
|
|
|
I would HIGHLY suggest picking up a book on remoting before you even attempt this. Otherwise your just wasting your time. For a game project like this, on a smaller scale, you don't have to use SQL server for anything. The server app can store all the session data it needs in memory.
The protocol is something you define. What does an IRC protocol know about your game? Nothing! So you have to write the rules of communication and what you want to communicate. That's the definition of a protocol...
You could use TCP/IP Sockets, .NET Remoting, WebServices, ... Like I said, pick up a book on these thing first. The best book is one YOU can understand, not the next guy on the board who's got 20 years of programming experience can could flip through the same book and in 20 minutes and call it "read".
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm feeling so sad.......
but thank you for your reply.
|
|
|
|
|
Alex Ngai wrote:
I'm feeling so sad
Why? Because you have to read a book on the subject? Because it is more challenging than you imagined?
Your bio says your a computer science major (excuse my lack of understanding on the US education system here) but doesn't that mean you are still at university? Surely you should be used to reading books. If I've misinterpreted and it means you've recently graduated then you have to realise that learning and educating yourself will not stop... EVER!
On the area of it being more challenging that you imagined then just think about what leanring the area will make of you. Imagine how much your overall understanding will improve. Think of all the extra employment opportunities that open to you when you can demonstrate knowledge in this area.
I hope this encourages you to continue with your project because I think once you understand how these technologies work you will probably find it isn't so hard.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
I'm feeling sad is because I need another computer
in order to do a multi-player feature in my game.
Since I don't have the money to buy another computer
for the server, that means I won't be able to do
what I wanted to do.
Yes, I'm still in University, and reading books is
part of my daily life. And because I'm still in
University, that means I'm poor.....err, yea!!
But thanks anyway, I think I will focus on other
aspect, and I'm going to cancel the multi-player
feature. By the way, if you know a way to avoid
the use of server, let me know.
Thanks
|
|
|
|
|
Don't be sad...read the remoteing and/or web services book(s).
In general, there's no reason why the "server" portion of the game has to reside on a physically seperate machine from your "client".
Bill
"it's all ball-bearings these days"
|
|
|
|
|
Like Bill Dean said, the server can run on the same machine as the client.
"Server" means more than just the hardware of a computer. The term more refers to the software that shares out its resources, or the resources of the machine on which it runs. But, being a Computer Science major, you already knew that, didn't you?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am having some trouble with setting a value to ComboBox.SelectedValue and then saving that value using DataBinding.
Example:
// There are five controls on a form, 1 ComboBox (comboBox), 2 TextBoxes (tbx1, tbx2) and 2 buttons (btnNew, btnSave)
DataSet dsFillCombo;
DataSet ds1;
// I fill each DataSet using separate data adapters
...
// The Combo is Bound like this
comboBox.DataSource = dsFillCombo;
comboBox.DisplayMember = "sectionIds.sectionName";
comboBox.ValueMember = "sectionIds.sectionId";
// So far, pretty basic. Now I bind the controls on the form to my other
// DataSet
tbx1.DataBinding.Add("Text", ds1, "users.fName");
tbx2.DataBinding.Add("Text", ds1, "users.lName");
comboBox.DataBinding.Add("SelectedValue", ds1, "users.sectionId");
BindingManagerBase bm = BindingContext[ds1, "users"];
// Still pretty basic, I could add more buttons to change the record
// position, and the values
// in the form controls would change with the data rows.
// Now for my issue!
// For the btnNew I want to add a new record to the dataset and set the
// comboBox to the same value that it is currently.
private void btnNew_Click(object sender, System.EventArgs e)
{
int i = Convert.ToInt32(this.comboBox.SelectedValue);
bm.AddNew();
this.comboBox.SelectedValue = sid;
}
// Now I click the Save button and...
private void btnSave_Click(object sender, System.EventArgs e)
{
bm.EndCurrentEdit();
}
As soon as I click btn_Save an Exception is thrown:
System.NoNullAllowedException: Column 'sectionId' does not allow nulls. ...
If I actually select a new value using the comboBox then the new record is saved without an issue.
Is there a way to set the SelectedValue of a ComboBox from code and have that value recongnized by DataBinding?
Thank you for any assistance.
Brett Slaski
|
|
|
|
|
Either assign DBNull.Value if the DataColumn allows nulls, or make sure it's assigned. Using a typed DataSet can help lay out the DataSet , though it's all programmatic and nothing you can do manually (just much easier using the designer, plus it adds a lot of extran functionality for you as well - especially with .NET 2.0).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It was suggested to me to use SelectedIndex instead of SelectedValue in my btnNew_Click method:
private void btnNew_Click(object sender, System.EventArgs e)
{
int i = Convert.ToInt32(this.comboBox.SelectedValue);
bm.AddNew();
this.comboBox.SelectedValue = sid;
}
>>>> Change to:
private void btnNew_Click(object sender, System.EventArgs e)
{
int i = this.comboBox.SelectedIndex;
bm.AddNew();
this.comboBox.SelectedIndex = sid;
}
Which this works great. I can preset the ComboBox to a value and it will be recognized by DataBinding, which isn't the case when you use SelectedValue. I just wonder how I would handle this if I don't know the index? If I have a langauge selector to default to the users preferred language, I know "EN" or "SP" but I don't know their index value. Is there a way to get this?
Brett Slaski
|
|
|
|
|
There's always almost an index. Even in a Hashtable (which, in itself, doesn't use indexes but buckets), you can get an index of a key or value at that time (changing the Hashtable may invalidate that if the number of buckets must be increased to handle the capacity, of course). Any IList implement defines IndexOf , which can help. That doesn't mean, of course, that it will work (you might get an NotSupportedException ), but every IList implementation I've ever worked with does define this method to do what it should.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm designing my first app in VS.NET using C#. I've created an outlook style toolbar down the side of my main form, and I want to change the content to the right of these buttons when the user clicks on the different buttons. I had it working fine with my toolbar buttons (which are custom and get deactivated every time I click on the design view) coded into Form1 but this is very cumbersome.
I want to use seperate UserControls for each of my content panels, and a seperate UserControl for my custom toolbar of buttons.
My problem is now one of referencing. I can't get my UserControl to tell Form1 to switch the visibility of my panels (change my panels).
This is how my main method gets the ball rolling:
static void Main()
{
Application.Run(new Form1());
}
So I don't know how to get ahold of an instance of my Form1 class so that my UserControls can say something like :
MyForm.SetVisiblePanel(panel_id);
Any suggestions?
also, what does the Form1_Load method do? VS seems to like to pop these methods in but they are empty.
|
|
|
|
|
You don't do anything in main. In your definition of Form1 , pass this (Form1 ) to the constructos of other controls or as properties. If those controls are children of that Form , cast the childrens' Parent properties to Form1 and access what you need to (so long as it's public or internal (public only within an assembly)).
It's all about keep references of objects assigned to variables and passing them as parameters. This is simple, straight-forward object-oriented programming.
What does Form1_Load do? If you look at your source code for Form1 , you'll see it's the event handler for the form's Load event. It was put there and is empty because you double-clicked the form at some point. VS.NET will automatically add an event handler for the default event when you double-click a control (like the Click event for a Button ). Visual Basic 6 was no different.
I recommend reading through some articles here and reading about the .NET Framework at http://msdn.microsoft.com/netframework[^]. Understanding these simple concepts is crucial to developing applications - not just coding programs.
There are also many examples of such applications that you're working on, such as A designable propertytree for VS.NET[^].
Abstraction also fits very nicely into such a model.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi every body
i want to ask:
how we can prevent the user from ending the process from the task manager?
the a second question is how we can make the service interactive with the desktop
i know that there is ServiceType calss but when i try to use it the service dos'nt interact with the desktop and here is the segment of the code which i wrote
..........
...........
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
//
// serviceInstaller1
//
this.st=System.ServiceProcess.ServiceType.InteractiveProcess;
this.serviceInstaller1.ServiceName = "Service2";
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1,this.st });
..............
..............
note i install the service by setup project
with regards
|
|
|
|
|
Wail A.Salem wrote:
how we can prevent the user from ending the process from the task manager?
You can't. But you can respond to notification that a user is killing your process. Handle the Closing or Close event of your main form (the one you pass directly or indirectly to Application.Run ). If your code is not finished in a timely manner, your process will be killed. There are a few other ways as well, but I'll leave this as an exercise for you. I recommend reading through the Windows Management APIs section of the MSDN Online Library[^].
As for the second question, you have to write this to the registry yourself. So add a registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\<YourServiceName>\Type such as 288 (256 for "Interact with desktop" OR'd with 32 for the service type), or whatever is appropriate for your service type so long as you perform a bitwise OR with 256 and run it as the LocalSystem (default). If you run it as a user, then the service can only interact with that user's desktop (assuming the user has an associated desktop session and can log in locally).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|