Windows Develop Bookmark and Share   
 index > Windows Forms General > DefaultNewRowValue dissapears
 

DefaultNewRowValue dissapears

Hi everybody!

I have to fill a column in a datagridview with a default value, therefore I have defined a custom column & celltype:

public class ColumnaCalendario : DataGridViewColumn
{
public ColumnaCalendario(): base(new CeldaCalendario())
{
}
}

public class CeldaCalendario : DataGridViewTextBoxCell
{
public CeldaCalendario() : base()
{
}

public override object DefaultNewRowValue
{
get
{
return DateTime.Today;
}
}
}

I have added a column of that custom type to my DataGridView, and new rows are supplied with a correct default value.
However, whenever I click on the new row, the default value dissapears and doesn't come back.

Any Ideas?

Thanks in advance.
sh4  Tuesday, September 22, 2009 11:21 AM
Hello,

Please post more code that demonstrates the problem.
Help someone to help you.

Rudedog =8^D
Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Wednesday, September 23, 2009 12:48 AM
Hello,

Please post more code that demonstrates the problem.
Help someone to help you.

Rudedog =8^D
Mark the best replies as answers. "Fooling computers since 1971."
There isn't more to explain.

That code for the custom column, and a grid with that custom column inside it.



Colabora con la comunidad, si éste mensaje te ha sido de utilidad, márcalo como respuesta correcta.
sh4  Wednesday, September 23, 2009 11:14 AM

Hi,

Sorry, I can’t reproduce.

I use the following code.

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

ColumnaCalendario cc = new ColumnaCalendario();

cc.Name = "test";

cc.HeaderText = "test";

dataGridView1.Columns.Insert(0,cc);

}

private void button1_Click(object sender, EventArgs e)

{

Console.WriteLine(dataGridView1.Rows[0].Cells[0].Value.ToString());

}

}

// copy your code

public class ColumnaCalendario : DataGridViewColumn

{

public ColumnaCalendario()

: base(new CeldaCalendario())

{

}

}

public class CeldaCalendario : DataGridViewTextBoxCell

{

public CeldaCalendario()

: base()

{

}

public override object DefaultNewRowValue

{

get

{

return DateTime.Today;

}

}

}

And When I click the cell:

( If you can’t see the image, you can click Image link: http://6gugmq.bay.livefilestore.com/y1pJG70tOc3Al0pTd3SnNcnpQIXRarPp0pizMfN2m7C59KKvjMapoYfUazPrktAbRLQghyR_uz8s4Js2zDBT6gZrCTrNg8Vn_UU/form7.jpg )

I think I must miss something. Could you please provide more details or make a demo project for us to test? Please upload your demo project to some server and offer us the URL. Skydrive (http://skydrive.live.com/ ) may be a good option. You can sign up 25GB free space only with your Windows Live Passport.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, September 28, 2009 3:37 AM

We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Sunday, October 04, 2009 7:33 AM

You can use google to search for other answers

Custom Search

More Threads

• window forms DataGridView in MFC Dilaog
• why MDA ingore wrong declaration of LOGFONT?
• Hiding my application from TaskManager
• Using ComboBoxes in a DataGrid
• tabcontrol scroll button
• Visual Studio 2008 Pro SP1 Hangs when editing WinForms
• VB.NET Arraylist of color names
• SQL Express Backup
• PropertyGrid - SelectedGridItemChanged
• Status Bar in COM Interop