Olukayode Oluwole
asked on
How can i extract 2 fields from a 3 field combo box record within a grid
I have a c# application with a Grid
I have a combo box withing the Grid displays 3 fields of a Record
Below is the Grid with the combo box
The combo is loaded with the code below:
dgvtxtentcode.DataSource = GlobalConfig.Connection.Ge tGradedIte mCodes_All ();
dgvtxtentcode.ValueMember = "ent_code";
dgvtxtentcode.DisplayMembe r = "FullTypeTabName";
The Display in the Grid is from the script below:
When i select a record from the combo I want to fill 2 fields in the grid as below
this.dgvDetailsTable.Curre ntRow.Cell s[1].Value = ent-_type
this.dgvDetailsTable.Curre ntRow.Cell s[2].Value = ent_code
In the first record ent_type = "A
and ent_code = "BASIC"
I am using the script below:
The problem is how do I extract "A" and "BASIC" from the string and place then in Grid columns 1 and 2
Thanks
Olukay
I have a combo box withing the Grid displays 3 fields of a Record
Below is the Grid with the combo box
The combo is loaded with the code below:
dgvtxtentcode.DataSource = GlobalConfig.Connection.Ge
dgvtxtentcode.ValueMember = "ent_code";
dgvtxtentcode.DisplayMembe
The Display in the Grid is from the script below:
public string FullTypeTabName
{
get
{
return $" {Ent_type} { Ent_code } {Ent_desc } ";
}
}
When i select a record from the combo I want to fill 2 fields in the grid as below
this.dgvDetailsTable.Curre
this.dgvDetailsTable.Curre
In the first record ent_type = "A
and ent_code = "BASIC"
I am using the script below:
if (SaveButton.Text == "Save")
{
// if (e.ColumnIndex >= 0 && Convert.ToInt32(PayRateIdValue.Text) > 0)
if (e.ColumnIndex > 0)
{
//var dgvDetailsTable = (sender as DataGridView);
//PayRateIdValue.Text = dgvDetailsTable.CurrentRow.Cells[8].Value.ToString();
switch (this.dgvDetailsTable.Columns[e.ColumnIndex].Name)
{
case "dgvtxtgradeamt":
this.dgvDetailsTable.CurrentRow.Cells[4].Value = FilterFieldValue.Text;
this.dgvDetailsTable.CurrentRow.Cells[0].Value = GradeIDValue.Text;
break;
case "dgvtxtentcode":
this.dgvDetailsTable.CurrentRow.Cells[1].Value = "A";
break;
}
}
}
The problem is how do I extract "A" and "BASIC" from the string and place then in Grid columns 1 and 2
Thanks
Olukay
In the second cell you have a combo-box and the content of this cell is established by the combo-box for the displaymember property, therefore, you cannot put other content in this cell, unless you change the property of the combo box. You have to use another mechanism to do it, for example, when right clicking on that cell, a contextual selection menu appears.
ASKER
You are right that i can only put one item in the second column
That was the reason i stated dgvtxtentcode.ValueMember = "ent_code";
That ensures that only the entrycode goes into that column.
I have tried right click as you suggested on column 2 and nothing was displayed
Am I doing something wrong
What i want is that while entrycode is written to column 2
ent-type should be written to column 1
How can i achieve this
Olukay
That was the reason i stated dgvtxtentcode.ValueMember = "ent_code";
That ensures that only the entrycode goes into that column.
I have tried right click as you suggested on column 2 and nothing was displayed
Am I doing something wrong
What i want is that while entrycode is written to column 2
ent-type should be written to column 1
How can i achieve this
Olukay
Why don't you use the combo-box description?
It is confusing to select a combo box option and then show me a different description than the one I chose.
The alternative of the contextual menu is to add the respective control to the winform and link it to the grid.
Another alternative is that you add
column next to the combo-box for the ent-code field. This column would be read only.
The last alternative is that you use a tooltip control with the long description for each item.
It is confusing to select a combo box option and then show me a different description than the one I chose.
The alternative of the contextual menu is to add the respective control to the winform and link it to the grid.
Another alternative is that you add
column next to the combo-box for the ent-code field. This column would be read only.
The last alternative is that you use a tooltip control with the long description for each item.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks