|
|
Can anyone give me a code snippet for how to move to the next column of a DataGridView to insert a value. In this case, there is no DB connectivity. I am creating an application that retrieves the property names and values for a control and populates a DataGridView with these values. I can do this:
foreach (PropertyInfo prop in t.GetProperties())
{
dataGridView1.Rows.Add(prop.Name);
dataGridView1.Rows.Add(prop.GetValue(controls[index], null));
}
However, this puts the values in the same column. I have 2 columns in the gridview, and would like the output to appear similar to the properties window in VS. Any help would be greatly appreciated. Thanks!
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
Create an array (say string[] ) of the data that you want to display. Then add it to the Rows collection of your DataGridView.
Check msdn[^] for the details about DataGridView.
*jaans
|
|
|
|
|
Hi,
Here is the code snippet:
foreach (PropertyInfo info in t.GetProperties())
{
dataGridView1.Rows.Add();
infoName = info.Name;
value = info.MemberType.ToString();
}
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Cells[0].Value = infoName;
dataGridView1.Rows[e.RowIndex].Cells[1].Value = value;
}
Thanks,
Gopal.S
|
|
|
|
|
Thank you kindly.
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
i want to create new menu type like a icons.
first time i create 2 icons then cliked in first icon, open 2 next icons
so on.
|
|
|
|
|
What you want sounds like a TreeView. Try inheriting from that.
Simon
|
|
|
|
|
no
i want to only icon not a windows or form. like desktop icons
|
|
|
|
|
Sorry then. I don't understand what you're trying to do.
Simon
|
|
|
|
|
i need to know how to get data from the DB and draw the graph in the application window directly.is there any tool i can use?
|
|
|
|
|
Use ADO.NET or Linq to get the data from the database.
If you're using winforms, override the OnPaint method in the form class, and draw onto the graphics object that is on the EventArgs parameter.
If you're using WPF, you can create a Canvas, and add UI elements too it like lines and rectangles by adding them to the Children on the canvas.
If you try to do this and have problems, come back with more specific questions.
Simon
|
|
|
|
|
If you don't want to spend time on creating graphics, then I suggest use Excel Object Library. You can find more on how to use excel with C# here.[^]
There's also an artical that shows how to create chart using Excel Object Library, but it's in J# but I think you should be able to do the same thing in C# with minor changes in your code. http://www.codeproject.com/KB/office/JExcel.aspx[^]
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
hy everyon!
i do have a little problem. i do have a function which has a parameter input as string. the input could be a number (double) or a date (datetime).
in this function i have to check, which input it contains. because depending on the input i have to do different things.
so i have to realize an if-then statement like
if (isdateformat)
{
}
if (isdoubleformat)
{
}
when using the convert function then the result is of this type (but i guess, if it is a double, then it throws an exception). when casting, then it is always of this type (always true).
could someone tell me please how to check the input of the string, if it is a date or a double?
thanks.
stephan.
|
|
|
|
|
stephan_007,
You can use RegEx or DateTime.TryParse / Double.TryParse.
Regards,
Gareth.
|
|
|
|
|
what does the statement look like?
because
DateTime dt;
datetime.tryparse(input, dt);
returns an error, it does not like the dt statement
|
|
|
|
|
stephan_007 wrote: returns an error, it does not like the dt statement
Funnily enough, compilers don't have emotions. It neither "likes" nor "dislikes" an argument! Do you mean it throws an exception? do you think this exception might be usful to us in trying to answer your question?
Have you tried the documentation for DateTime.TryParse? If you did you'd see the second parameter is defined as an out parameter.
<br />
DateTime dt;<br />
datetime.tryparse(input, out dt);
|
|
|
|
|
ups stupid me
yes you are right, now it works
|
|
|
|
|
Use DateTime.TryParse()
My idea of ideal life : Eat, Sleep, Repeat
|
|
|
|
|
hi,
you want to check data type of parameter.
solution:
string sf = "hello";
double d = 34.3;
if (sf is string)
MessageBox.Show("String");
else
MessageBox.Show("SF not string");
if (sf is double)
MessageBox.Show("double");
else
MessageBox.Show("SF not double");
if (d is string)
MessageBox.Show("string");
else
MessageBox.Show("dnot string");
if (d is double)
MessageBox.Show("double");
else
MessageBox.Show("d not double");
|
|
|
|
|
Why is the function using a string as parameter? That means that you have to convert all values to strings, then parse them back to the values again.
Make the parameter an object instead, then you can easily check the actual type of the value:
public int SomeFunction(object value) {
if (value is DateTime) {
DateTime d = (DateTime)value;
...
} else if (value is double) {
double d = (double)value;
...
} else {
throw new ArgumentException("Type "+value.GetType().Name+" is not accepted as parameter.");
}
}
Using an object parameter to accept value types means that the values will be boxed. Boxing is something that you generally want to avoid if possible, but in this case there is no common base type between DateTime and Double that you could use instead. Also, converting to a string and back is far worse than boxing.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Friday, May 2, 2008 9:04 AM
|
|
|
|
|
I think I asked him that same thing a few days ago.
|
|
|
|
|
Hi All,
I need to write document for C# Code Standards.Anybody who is having idea about any article regarding the same?
With Regards
|
|
|
|
|
You mean like this[^] ? Second google hit, probably first hit if I searched CP directly.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
There are various books out there on the subject already. Our policy was just to use the standards in the book - it saved us a lot of time writing standards.
|
|
|
|
|
Colin Angus Mackay wrote: Our policy was just to use the standards in the book - it saved us a lot of time writing standards.
Very much true. It saves a lot of time and effort.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|