|
and you want to ensure you have sufficient locking on the table, for both the read and the write. If two people perform the same operation at the same time, they might both be given the same 'new' key.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Hello,
I'm hoping someone can help me out here.
I want to get started using DataGridView, but I've not actually managed to find any examples that fit what I'm trying to do.
What I want to do is very simple:
(1) I have a list of class instances thus:
<br />
List<MyClass> classList = new List<MyClass>();<br />
<br />
classList.Add(new MyClass("Fred"));<br />
classList.Add(new MyClass("Wilma"));<br />
<br />
etc
(2) I want each MyClass member of classList to be represented as a row in my DataGridView
(3) I want to show only a subset of the class parameters, for example:
<br />
public class MyClass<br />
{<br />
private string name;<br />
private string desc;<br />
<br />
private int anumber;<br />
<br />
public String Name<br />
{<br />
get { return (name); }<br />
set { name = value; }<br />
}<br />
public String Description<br />
{<br />
get { return (desc); }<br />
set { desc = value; }<br />
}<br />
<br />
<br />
<br />
public int Number<br />
{<br />
get { return (anumber); }<br />
set { anumber= value; }<br />
}<br />
}<br />
I understand that I need to set the DataSource parameter of my DataGridView to my data, in some way, but I don't seem to be able to get it to work. Do I need to do something to my classes to get it to work?
I think that sums it up. No SQL, nothing just a nice list of data that I want to display.
Can anyone help? Many thanks!!
|
|
|
|
|
Hi,
Use a binding source to bind your list and then bind the binding source to the data grid view.
dataGridView1.DataSource = bindingSource1;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
this.bindingSource1.DataSource = myList;
Thanks and Regards
Mahen
|
|
|
|
|
Please don't cross post. You asked this same question only two hours ago. It is rude to cross post just because no one answers right away.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
And even ruder to then delete the mail leaving you dangling in the forum!
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Malcolm Smart wrote: even ruder to then delete the mail leaving you dangling in the forum!
Yeah, those are pretty bad, too.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
hi there,
i put a progress bar in my app, its working well, but when i click outside the app then app becomes white, that mean it look like the non responding prog. but its working in backgroud
i wanna know how can i make it that it should look working app?
Becoming Programmer...
|
|
|
|
|
To xmen_xwk,
you can use "Application.DoEvent();" at each loop.
---------------------------------
Believe what you saw!
|
|
|
|
|
thanks dude
Becoming Programmer...
|
|
|
|
|
Use a backgroundworker to do the work, which can then report progress to the gui thread so you can update the progress bar
I have no blog...
|
|
|
|
|
I new C# programmer and I'm attempting to write a FAST generic method that would takes types like short, int, long, float, double etc.... and put them in a byte array at a specified index. It would allow you to specify the endianess you want. I have seen a couple of answers out on the forums, but they all appeared to be handing the of data (or byte arrays)several times. I could define the same method with the specific type I want use and it will compile but then I need to duplicate this for every type that I want to use. I was hoping I could get some help on this so the method is both fast and easy to maintain.
The following is what I would like to do but it doesn't compile because "Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')":
public unsafe static void IntoBytes2 <T> (byte[] byteArray, int index, T data, bool MSBFirst) where T : struct
{
byte* dataPtr = (byte*)&data;
if ((index + sizeof(T) - 1) <= byteArray.Length)
{
if (MSBFirst)
for (int i = index + sizeof(T) - 1; i >= index; i--, dataPtr++)
{
byteArray[i] = *dataPtr;
}
else
for (int i = index; i < index + sizeof(T); i++, dataPtr++)
{
byteArray[i] = *dataPtr;
}
}
}
Thanks for any help
- Nick
|
|
|
|
|
My first question would be why are you trying to reinvent the wheel?? This is already possible in the .NET Framework using the BitConverter class and Serialization using the BinaryFormatter.
|
|
|
|
|
That would perfect if the byte array was in little endian byte order. However, the data that I'm looking at is in big endian format.
Example:
The byte array looks like this: { 0, 0, 0, 1, 0, 0, 0, 3} and I need to convert the first four bytes into a 0x1 and the next four bytes into a 0x3.
I know I could do it with bitConverter and then reversing a temp array and then storing back into the original, but thats a lot of data movement.
I want to keep this as effecient as possible.
It would have been great if they would have supplied a boolean option to the BitConverter to state what kind of byte order your dealing with for input (from byte array) or output (to an array).
I very new at C# so please be patient with me (as my name suggest).
Thanks,
Nick
|
|
|
|
|
|
Ahh, you beat me to it!
|
|
|
|
|
So what I'm hearing (from the article) there is no good (and fast) solution other than possibly using the System.Net.IPAddress.HostToNetworkOrder/NetworkToHostOrder which appears will work for 4 bytes or less (shorts, int); but will it work for values that are stored in 8 bytes (doubles)?
Even with the host/network order if your class already has an byte [] defined you'll now you have to copy the return getbytes array into it!
This sure would have been so much easier if they supplied a flag parameter on the getbytes and other BitConverter routines. Along with a new method (same as getbytes) but returns a void and updates a destination array at a specified index for a value that you pass it: example: BitConverter.PutByte(destArray, destIndex, value, reverseEndianess);
I definetly use the network/host order To<type> to at least convert my bytes to a value. Still wondering if it will work for doubles?
Thanks.
|
|
|
|
|
I thought the host/network was a toggle for endianess. It's not. I didn't look at the source code but I suspect is basically doing the same thing that was mentioned in the article. And it will only work for 4 byte and 2 byte values.
Any other ideas? Otherwise I guess I will just un-generic my code and keep duplicating as needed.
(Sucks!)
|
|
|
|
|
Hi guys,i hope to learn how i can create a new textbox with checkbox or button.i want to create in same form.i want when i click button or checkbox ,form create a new textbox
|
|
|
|
|
In your button/checkbox event handler, create a new instance of a System.Windows.Forms.TextBox and add it to your form's controls collection using the Controls.Add method.
Paul Marfleet
|
|
|
|
|
thx a lot man...but what should i write in Controls.add("here") ???
|
|
|
|
|
try this :
private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.TextBox textBox1 = new System.Windows.Forms.TextBox();
textBox1.Location = new System.Drawing.Point(81, 110);
textBox1.Name = "textBox1";
textBox1.Size = new System.Drawing.Size(100, 20);
textBox1.TabIndex = 1;
this.Controls.Add(textBox1);
}
Becoming Programmer...
|
|
|
|
|
Hi,
I have some Rich Text Control that i use as label ( im not using Static label because i need to change the color and font of some chars ) that i set to it in Run Time some String.
In case the string is too long ( the size of the Rich Text label is not auto size ( i mean that the size is const ) ) there will be some Tool Tip with the all string.
My question is ... how can i know if the string is too long ?
Is there is some way ?
Thanks for any help.
|
|
|
|
|
int stringlenght = rtb.Length;
Becoming Programmer...
|
|
|
|
|
This will bring back the string lengh of the all rich text ... and this is not what i need.
|
|
|
|
|
RTB.Text.Length would give the number of actual characters; that is good enough when
using a non-proportional font.
For proportional fonts, this may do it:
create a second but invisible RTB with AutoSize, give it the same text, read its Width,
compare with the Width you gave the original RTB and act accordingly.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|