Datagridview and Dynamic Array
Hi Guys
I need some help here because I am very very new to C#.
I have a datagridview with 41 columns, and I need to assign
column 0 and all its cells as integer only. How do i do that?
Also, how do i clear public string array after getting values from a splilt?
I need to clear the array to pump in new values, making the array dynamic.
Perhaps i am doing things wrong here, can anyone help?
Thanks
Re: Datagridview and Dynamic Array
These are unrelated questions and should have been asked in separate threads.
For the grid, there is nothing to do. The DataGridView is basically for displaying data in embedded controls. If you want the grid to prevent the user entering anything but numbers then you'd have to embed a control that only accepted numbers. That would mean creating your own column type to embed a NumericUpDown control or a customised TextBox. That's probably more trouble than you need to go to. You should just bind the grid to a data source where the property bound to that column is type Integer. That would mean binding to a DataTable with a DataColumn of type Integer or an array or collection of objects whose type has an Integer property. An exception will then be thrown if the user enters an invalid value. You can catch that exception and either force them to enter a valid value or cancel the change.
As for the second question, you won't be clearing any arrays. The Split method returns a string array object. It doesn't fill an existing array. That means that every time you call Split it will create a new array and return it. If you're splitting multiple arrays then you simply discard each one when you're done with it, e.g.
Code:
string[] words;
foreach (string line in File.ReadAllLines("file path here"))
{
words = line.Split(' ');
// Use 'words' here.
}
Re: Datagridview and Dynamic Array
Hi.
I got some codes with Custom formatting for datagridview.
Will try to do so.
i have replaced the array with structures and list. Made my Life a little easier.
Thanks for the guide!