|
Hi,
Project
-------
I have this list box that will get a list of items from a database. Upon choosing an item, it will populate the DataGridView with the data, this data is different for different items, e.g. one might have a size field and another wouldn't or an item might have 5 entries but another 9, etc. This populated data is from a table that has a unique ID (key), the field name, the field value and the foreign key to link to the item table.
Problem 1
---------
Currently, I'm trying to add an item into the database, how can I create a DataGridView that would allow me to add rows to it. If I bind it to a table I get the error that table.rows.add() is not allowed on a bound DataGridView.
I have to presume that I can just unbind the table and add the rows of data manually. I'm wondering if there is an easier way of doing it.
Problem 2
---------
Further to the above, if I want to edit an item, how can I go about adding a new row if the columns are bound. I require (during editing) that columns because more than 1 user might be editing the same item at the same time.
How would I go about doing this?
Anyone has any article to point me to?
Thanks.
Desmond
|
|
|
|
|
Answer to problem 1
-------------------
1. Add a datagridview to your form.
2. Dont add any column to it
add a quote to retrieve data from the database
1. connectionstring
e.g string conStr="Add the relevent connection to the database"
2. a function to retrieve the data. Create a class called it DataAccess
<code>
using system.data;
using system.data.oleddb;
public class DataAccess
{
public void Show(string sql, string con, datagridview dt)
{
}
}
</code>
Then you can call this class to pupulate any datagridview with any number of rows or columns without any modifications. If you want a complete quote let me know (lnkgoeng@webmail.co.za)
|
|
|
|
|
Hi all!
I´m trying to make a barcodeprinting and to make it possible i have to have a page foreach items in my listview.
my code look like this:
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
PrintDialog theDialog = new PrintDialog();
theDialog.Document = printDocument1;
if (theDialog.ShowDialog() == DialogResult.OK)
{
printDocument1.DocumentName = listView1.Items.Count.ToString();
printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
printDocument1.Print();
}
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
foreach (ListViewItem lvi in listView1.Items)
{
DateTime dt = DateTime.Now;
string doktyp = "278";
Font font = new Font("3 of 9 Barcode", 20);
int St = Convert.ToInt32(domainUpDown1.Text);
Font font1 = new Font("Arial", St);
Font font2 = new Font("Arial", 10);
float x = 120;
float y = 100;
e.Graphics.DrawString("Jobb: " + label11.Text, font2, new SolidBrush(Color.Black), x + 500, y - 50);
e.Graphics.DrawString("Användare: " + label12.Text, font2, new SolidBrush(Color.Black), x + 500, y - 35);
e.Graphics.DrawString(dt.ToString("yyyy-dd-MM HH:mm:ss"), font2, new SolidBrush(Color.Black), x + 500, y - 20);
e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 85);
e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 105);
e.Graphics.DrawString("*" + lvi.SubItems[1].Text + "*", font, new SolidBrush(Color.Black), x, y + 125);
e.Graphics.DrawString(lvi.SubItems[1].Text, font1, new SolidBrush(Color.Black), x, y + 145);
}
}
With this code it overwhrites all the items in one page.
Thanks!
Best Regards André
|
|
|
|
|
Well, that's what you're telling it to do. You don't actually set x anywhere that I can see. It looks to me like all your labels will print in one location, because that's what your code does. x and y need to change to move your labels.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
yes i know.. but i want it to be on print page2 in the same position like page1.
Regards!!
|
|
|
|
|
In c#.net which namespace and classes and method use to control the hardware of my computer i,e i want to develop a c# program which can use for eject the cd rom of my computer without and manualy touch.if possible plz sent a demo program to understand the uses of namespace,classes and method .
|
|
|
|
|
You need to read up on how to ask questions. About C#.NET is not a worthwhile header.
There are namespaces that may help you, but I suspect you're going to end up pinvoking C APIs www.pinvoke.net[^] is a good place to start
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Hi,
I have started looking at LINQ lately...
I can see that learning LINQ will indeed reduce the coding I do at present...
Questions:
1)
Do you think LINQ is the way forward? Will it be in demand in the near future?
2)
It's just that I do not see or hear any projects requiring the knowledge of LINQ.
So, should I really invest more time to learn LINQ? I do not miind doing this if I know it will be in demand...
Thanks
|
|
|
|
|
1 - LINQ is probably resume fodder, and will most likely be used for all sorts of things it's not good for, before things settle down and it just becomes a tool in the toolbox.
2 - I can't percieve of a project NEEDING LINQ. It's just syntactic sugar. There are good reasons not to use it ( one, if you're the only one on a team who can read the code ). But, I still am trying to carve out time to know it better and to be able to use it myself.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
For the most part, I agree with what Christian said.
1. LINQ is still very new and all of the guidance around when it should be used isn't in place yet. There is a lot of power and flexibility behind LINQ and the concepts taht are in place to support it, like extension methods and lambda expressions. Most of those language features will eventually just become another tool, in the same way foreach has.
2. There will never be a project that requires LINQ. Everything that can be accomplished using LINQ can be accomplished in more traditional manners as well, although it may be easier using LINQ or some of the LINQ related language features.
In my opinion, you're better off knowing how the supporting language features work (extension methods, lambdas, inferred typing, and object initializers) and what you can do with them. LINQ is a pretty big topic (LINQ to SQL, Entities, XML, etc...) but the supporting features are all the same no matter what.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Not really important, but I'm just curious.
Say that you want to print something to a log if a global boolean (condition) variable is set.
How would you do it?
1)
if(condition)<br />
CallLogMethod("Message");
OR
2)
CallLogMethod("Message");
and in the method body put
if(!condition)<br />
return;
The first makes the code more bloated if used intensively, while the second uses the call stack even though it might not do anything.
So how would you do it?
|
|
|
|
|
I'd go with 2. My dual core CPU can handle it. My number 1 priority is bug free code that's easy to use.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
There is a third option:
CallLogMethod(condition, "Message") The CallLogMethod still evaluates the condition, but it gets passed in. This is similar to how Debug.WriteLineIf works.
In either case, I would go with option 2 or 3 and push the test into the method itself. This way, you guarantee that it will always be tested and tested the same way and it's one less thing to worry about at the calling site.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hi,
I'm using a PropertyGrid on my custom property class. I want to dynamicly set a property to ReadOnly or hide it.
How do I do this?
Gr.
|
|
|
|
|
[ReadOnly]
public bool Foo {get;set;}
[Browsable(false)]
public bool Bar {get;set;}
|
|
|
|
|
I'n not sure what I'm suppose to do here.
When I add [ReadOnly] to my property I get an error.
I tried something like [ReadOnly(Foo)] but that not allowed either.
Could you give me a bit more described answer.
Thanks
modified on Tuesday, July 1, 2008 4:28 AM
|
|
|
|
|
using System.ComponentModel;
[ReadOnly(true)]
or
[ReadOnly(false)]
|
|
|
|
|
Well I think i haven't been very clear.
I know this. But I want to change this Dynamicly. By that I mean I wan't to change this at runtime by clicking on a button or something.
|
|
|
|
|
Well you should flippen well ask that! And why vote me down when I gave you the correct answer for your original question?
The answer is you cant do that. (You can probably but that will require a lot of work, and I have not gone down that route).
|
|
|
|
|
Well sorry for voting you down but your answer wasn't verry complete and I thought the word Dynamicly made it pretty clear I wasn't looking for a static solution.
But we might disagree on that one.
Although I found a project in wich it is done (link[^]), this was way to complex for me so I'm using a workaround now.
Anyway thanks for your reply. and sorry again for the "down voting".
|
|
|
|
|
KBou wrote: Although I found a project in wich it is done (link[^]), this was way to complex for me so I'm using a workaround now.
That's what I thought
KBou wrote: I thought the word Dynamicly made it pretty clear I wasn't looking for a static solution.
Dynamic can mean a lot
KBou wrote: Anyway thanks for your reply. and sorry again for the "down voting".
No problem
|
|
|
|
|
hi every buddy,
I'm working in an ASP .NET project and in that I need to generate a unique key which is to be used instead of the primary key in the database of 6 digits and it should be random in nature yet it should be unique ofcourse. Actually the client doesnt want to issue numbers such as 000001, 000002... he wants it to be like 872731. The problem in my mind is that how are we gonna generate these unique but random numbers, coz whats bugging me is: WE would have to check for the keys already taken and 1) its v inefficient and 2) it could have problems with concurrency.
So I really need to guidelines from you people, I would definately appreciate this. Thank you.
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
Why do people insist on this anti-pattern?
You will likely need to persist all the id's in a table, then just create random number, check for uniqueness on table, repeat if necessary, add newly created number. For concurrency, you will probably need to lock the table or something.
|
|
|
|
|
leppie wrote: Why do people insist on this anti-pattern? [Frown]
hmm didnt get that one! honestly.
now comming to the point. I really dont think locking a table would be a great idea from an ASP .NET app. I may be wrong. Do u think I can generate the random numbers from TSQL?
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|