HighTechTalks DotNet Forums  

DataGridView Button Column Text

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss DataGridView Button Column Text in the Dotnet Framework (WinForms Controls) forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
JT
 
Posts: n/a

Default DataGridView Button Column Text - 05-23-2006 , 06:39 PM






Hi,
I am "upgrading" from the datagrid to the datagridview. I currently use a
datagrid button column that allows me to set the button text property. The
click handler for the button column gives me access to the underlying
datacolumn's value at a given row. I then use this value to open other
forms, as a parameter for sqlCommands, etc.
In the datagridview button column, it appears that setting the Text property
for the button does not work unless you state that the button value will
equal the button's text property. The alternative is to not set the text
property, in which case the button will display the columnvalueAtRow. This
value, in my case, is usually an identity column integer, which I do not want
to display to the user. For example, rather than have a button text read
'7663', I would prefer it read 'RESET', and that by clicking it I could
retrieve the 7663 value.
Is there a way to do this? Thanks.

--
John



Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default RE: DataGridView Button Column Text - 05-23-2006 , 11:51 PM






Hi John,

Thank you for posting.

If you set the DataPropertyName of the DataGridViewButtonColumn to a field
of a datatable, the buttons in cells will display the field value of the
datatable in the button text. If you set the Text property of the
DataGridViewButtonColumn to a text(e.g "RESET") and set the
UseColumnTextForButtonValue property to true, every button cell will
display the same button text(in this case, "RESET").

If you want to display "RESET" button text in every button cell and
retrieve a value in the corresponding row, please set the Text property of
the DataGridViewButtonColumn to "RESET" and set the
UseColumnTextForButtonValue property to true and add the following code in
the DataGridView's CellContentClick event handler.

private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
DataRowView datarow =
(DataRowView)this.dataGridView1.Rows[e.RowIndex].DataBoundItem;
int columnvalue = (int)datarow["SomePropertyInDataTable"];
......
}

Hope this is helpful to you.

If you have any concerns or need anything else, please don't hesitate to
let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==


Reply With Quote
  #3  
Old   
JT
 
Posts: n/a

Default RE: DataGridView Button Column Text - 05-24-2006 , 01:26 AM



Thanks Linda. You're both awesome and prompt! Could I ask one more
question...
Does the datagridviewComboBoxColumn control exhibit Intellisense? If not,
can you point me to an example of how to create a custom dataGridViewColumn?
(I have a DataGridComboBoxColumn that I created that does exhibit
intellisense that I would like to upgrade). Thanks.
--
John


"Linda Liu [MSFT]" wrote:

Quote:
Hi John,

Thank you for posting.

If you set the DataPropertyName of the DataGridViewButtonColumn to a field
of a datatable, the buttons in cells will display the field value of the
datatable in the button text. If you set the Text property of the
DataGridViewButtonColumn to a text(e.g "RESET") and set the
UseColumnTextForButtonValue property to true, every button cell will
display the same button text(in this case, "RESET").

If you want to display "RESET" button text in every button cell and
retrieve a value in the corresponding row, please set the Text property of
the DataGridViewButtonColumn to "RESET" and set the
UseColumnTextForButtonValue property to true and add the following code in
the DataGridView's CellContentClick event handler.

private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
DataRowView datarow =
(DataRowView)this.dataGridView1.Rows[e.RowIndex].DataBoundItem;
int columnvalue = (int)datarow["SomePropertyInDataTable"];
......
}

Hope this is helpful to you.

If you have any concerns or need anything else, please don't hesitate to
let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==



Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default RE: DataGridView Button Column Text - 05-24-2006 , 02:44 AM



Hi John,

Thank you for your response.

Would you tell me how you'd like the DataGridViewComboBoxColumn to exhibit
intellisense? Could you explain the phrase "exhibit intellisense" to me
more in detail?

For an example of how to create a custom DataGridViewColumn, you could
refer to the following link.

http://msdn2.microsoft.com/en-us/library/ms180996(VS.80).aspx

Hope this is helpful to you.
If you have concerns or need anything else, please don't hesitate to let me
know.


Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==


Reply With Quote
  #5  
Old   
Shortie
 
Posts: n/a

Default RE: DataGridView Button Column Text - 03-27-2007 , 09:09 PM



Hi Linda. I see your answer for a databound column. My column is unbound
and I'm having the same issue. I'd like the cells to be able to contain
something complex (like a delimited string that represents an array of data)
and have the button say "Edit" which then pops up a dialog box for editting.

The only way I've found to make this work is that in the CellContentClick
event handler, I temporarily set UseColumnTextForButtonValue to false. Then
I pop up the dialog, put the new complex value into the cell, and then set
UseColumnTextForButtonValue back to true. This seems very kludgy, not to
mention the fact that it looks ugly since you can see the DataGridView in the
background with the delimited string displayed on the button faces while the
dialog is active.

Any ideas?

"Linda Liu [MSFT]" wrote:

Quote:
Hi John,

Thank you for posting.

If you set the DataPropertyName of the DataGridViewButtonColumn to a field
of a datatable, the buttons in cells will display the field value of the
datatable in the button text. If you set the Text property of the
DataGridViewButtonColumn to a text(e.g "RESET") and set the
UseColumnTextForButtonValue property to true, every button cell will
display the same button text(in this case, "RESET").

If you want to display "RESET" button text in every button cell and
retrieve a value in the corresponding row, please set the Text property of
the DataGridViewButtonColumn to "RESET" and set the
UseColumnTextForButtonValue property to true and add the following code in
the DataGridView's CellContentClick event handler.

private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
DataRowView datarow =
(DataRowView)this.dataGridView1.Rows[e.RowIndex].DataBoundItem;
int columnvalue = (int)datarow["SomePropertyInDataTable"];
......
}

Hope this is helpful to you.

If you have any concerns or need anything else, please don't hesitate to
let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.