How do you get the value (not display value) of a dropdown box in a datagrid? Been using
memberRowIndex = (Me.grdGroup.CurrentCell.RowIndex())
Me.grdGroup(memberRowIndex, 1).CellValue
to get the text value of the dropdown box in the datagrid. Need the value (int) not the text string.
Thanks,
Dan
AD
Administrator
Syncfusion Team
September 12, 2005 11:22 PM UTC
To get the value, you should use grid(rowIndex, ColIndex).CellValue. To get the display value, you should use grid(rowIndex, ColIndex).FormattedText.
In our \Syncfusion\Essential Studio\3.3.0.0\Windows\Grid.Windows\Samples\DataBound\GDBGcombos sample, if you add a button to the form with this button handler, it displays the ValueMember and the DisplayMember as expected.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Console.WriteLine(Me.gridDataBoundGrid1(1, 2).CellValue)
Console.WriteLine(Me.gridDataBoundGrid1(1, 2).FormattedText)
End Sub
EL
Elsa
May 31, 2006 11:37 PM UTC
Hi! I''ve been also trying to figure out how to retrieve the value (ValueMember) from the combo box. I followed your instructions and I am not able to see a different value for the CellValue and the FormattedText properties of the cell. These have the same values:
(string)grdImport[CurrentRow, COLUMN_CLIENT_STUDY_NAME].FormattedText
(string)grdImport[CurrentRow, COLUMN_CLIENT_STUDY_NAME].CellValue
I set each row''s combo box with the following:
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].DataSource = clientStudyListItems;
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].DisplayMember = "Name";
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].ValueMember = "DatabaseName";
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].ExclusiveChoiceList = false;
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].CellValue = clientStudyListItems[selectedIndex].Name;
where the DataSource is a custom class (attached). Is there anything that I am missing? Thanks in advance!
AD
Administrator
Syncfusion Team
June 1, 2006 04:53 AM UTC
Hi Elsa,
You need to set the cellvalue property of the cell in a grid to value member value. Here is a code snippet.
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].DataSource = clientStudyListItems;
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].DisplayMember = "Name";
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].ValueMember = "DatabaseName";
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].ExclusiveChoiceList = false;
///>>>>>>>end Modification<<<<<<<<<<<<<<<<
/// DatabaseName is a valuemember
grdImport[rowIndex, COLUMN_CLIENT_STUDY_NAME].CellValue = clientStudyListItems[selectedIndex].DatabaseName;
///>>>>>>>End Modification<<<<<<<<<<<<<<<<
Please let me know if this helps.
Regards,
Haneef
EL
Elsa
June 1, 2006 01:44 PM UTC
Thanks for your prompt response! I think I''m getting closer to a solution with your help. I did change the code as you suggested. Now, when I go to the next page (by clicking on a button), the display text changes to the value. Is there a way to capture an event when the display text changes its value to see what is changing it? Thank you very much!
AD
Administrator
Syncfusion Team
June 2, 2006 05:34 AM UTC
Hi Elsa,
To get the current cell new value, you should use Renderer.ControlValue. To get the current cell new display value, you should use Renderer.ControlText . You need to assign the renderer''s controltext in a button''s click event to fire the current cell changed event. Here is a code snippet
private void button2_Click(object sender, System.EventArgs e)
{
this.gridDataBoundGrid1.CurrentCell.MoveTo(1,1);
//You need to assign the controlText to fire the CurrentCellChanged Event.
this.gridDataBoundGrid1.GetCellRenderer(1,1).ControlText = "3";
this.gridDataBoundGrid1[1,1].Text = "3";
this.gridDataBoundGrid1.RefreshRange(GridRangeInfo.Cell(1,1));
}
private void gridDataBoundGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
string s = "New Display Text :" + cc.Renderer.ControlText + Environment.NewLine +
"Old Display Text :" + this.gridDataBoundGrid1[cc.RowIndex ,cc.ColIndex].FormattedText;
MessageBox.Show(s);
}
Here is a sample.
http://www.syncfusion.com/Support/user/uploads/ComboGDBG_a6163c22.zip
Let me know if this helps.
Regards,
Haneef
EL
Elsa
June 2, 2006 01:05 PM UTC
Thank you for all your help! You''re awesome!