Hello Brother,
Quote:
The User should click on the Cell and edit the Cell by using his keyboard.
Is a DataGrid the right thing for doing this? And How can I realize this?
You can do this using TablelayoutPanelControl. I feel it is much more flexible(Please correct me if i am wrong).
In a tablelayoutpanel control you can add controls you like to generate a template. I can even generate a form with textboxes and buttons.
In your case you want to generate a table of 3 rows and 20 columns so:
On Form Load:
private void Form1_Load(object sender, EventArgs e)
{
tableLayoutPanel1.ColumnCount = 20; tableLayoutPanel1.RowCount = 3;
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 3; j++)
{
tableLayoutPanel1.Controls.Add(new TextBox(), i, j);
}
}
}
- But please note when you add a tablelayoutpanel control to the form, make sure that you "autosize" both its rows and columns. Because by default the tablelayoutpanel control only renders 2 columns.
- To do that you need to right click on the tablelayoutpanel select the rows option and set the size mode to autosize. Similarly you need to do that for columns also.
- Again recheck if the Autosize for Rows and Columns has been set or not. If not, do it again.
- If the number of rows and columns increase then while rendering the application may reach into a non responsive state. So you need to use a background worker for that. I have just suggested you a control and the logic.
- Also its a very wrong thing to perform any action on FormLoad (which i have done here)best is to initialize a thread in the background, that thread will render the control on the form. Use backgroundworker. Please read about background worker in depth. Its very helpful when you want to render many things on UI amd perform any operation also.
Refer:
BackgroundWorker Class Sample for Beginners[
^]
And please dont mind: A small homework: Try to make this application dynamic. Accept the row and column count from textboxes :)
Please do tell me whether the code i posted works or not?
Thanks,
- Rahul