Olukayode Oluwole
asked on
How do i write Values from a List and combo to a DataGrid
I have a c# application in which i am trying to
write values from a list and a combo into a grid and later on to save it.
The grade level is loaded to a List Box while
The Entry codes are loaded to a combo (within the Grid) see attached screen
I have a problem specifying the the statement that will move the items from the List and Combo
to the Grid.
I believe the first issue is the fact that the script attached below is not under the right event
as i am not able to address the Currentrow under this event.
1. Which event should i use to ensure i have access to the Current row so that my selections
will be writing on the current row
2. I am casting the Model Proportion Model to a Combox ( loaded within the grid )
Is this correct or i should be casting the model to a DataGrid instead ( see code below )
3. What would be correct syntax for the 2 lines flagged as error (see screen below)
I will appreciate suggestion to enable me resolve this issue
Regards
Olukay
write values from a list and a combo into a grid and later on to save it.
The grade level is loaded to a List Box while
The Entry codes are loaded to a combo (within the Grid) see attached screen
I have a problem specifying the the statement that will move the items from the List and Combo
to the Grid.
I believe the first issue is the fact that the script attached below is not under the right event
as i am not able to address the Currentrow under this event.
1. Which event should i use to ensure i have access to the Current row so that my selections
will be writing on the current row
2. I am casting the Model Proportion Model to a Combox ( loaded within the grid )
Is this correct or i should be casting the model to a DataGrid instead ( see code below )
private void dgvDetailsTable_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
string varentcode = "";
string varenttype = "";
var data = (sender as ComboBox).SelectedItem as ProportionsModel;
varentcode = data.Ent_code;
varenttype = data.Ent_type;
Convert.ToString(dgvDetailsTable.CurrentRow.Cells["txtcmbCode"]) = data.Ent_code;
Convert.ToString(dgvDetailsTable.CurrentRow.Cells["txtenttype"]) = data.Ent_type;
}
}
3. What would be correct syntax for the 2 lines flagged as error (see screen below)
I will appreciate suggestion to enable me resolve this issue
Regards
Olukay
ASKER
Thanks Gustav.
I have redone the code and currently have no syntax issues (see code script below)
But I have an issues of where to put it .
I have tried the 2 events above but the result is not satisfactory
Under
private void dgvDetailsTable_CellValueC hanged(obj ect sender, DataGridViewCellEventArgs e)
The form does not load because it keeps seeing a null reference for the combo which during load is empty.
under
private void dgvDetailsTable_CellDouble Click(obje ct sender, DataGridViewCellEventArgs e)
the form loads but getting the mouse double click event to fire has not worked properly.
What i want is that the form form should load first with the List and Combo populated
Then when ever i select a value from the combo the 4 values in the grid should be populated on that particular line.
In other words if i stay on a line and keep changing the combo values the 4 grid values should keep changing.
under which even should i put the script
Thanks
olukay
I have redone the code and currently have no syntax issues (see code script below)
private void dgvDetailsTable_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//if (e.ColumnIndex == 1)
//{
// string varentcode = "";
// string varenttype = "";
// var data = (sender as ComboBox).SelectedItem as ProportionsModel;
// varentcode = data.Ent_code;
// varenttype = data.Ent_type;
// dgvDetailsTable.CurrentRow.Cells["txtcmbCode"].Value = varentcode;
// dgvDetailsTable.CurrentRow.Cells["txtenttype"].Value = varenttype;
// dgvDetailsTable.CurrentRow.Cells["txtgradelevel"].Value = GradeLevelValue.Text;
// dgvDetailsTable.CurrentRow.Cells["txtFilterType"].Value = FilterFieldValue.Text;
//}
}
private void dgvDetailsTable_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
string varentcode = "";
string varenttype = "";
var data = (sender as ComboBox).SelectedItem as ProportionsModel;
varentcode = data.Ent_code;
varenttype = data.Ent_type;
dgvDetailsTable.CurrentRow.Cells["txtcmbCode"].Value = varentcode;
dgvDetailsTable.CurrentRow.Cells["txtenttype"].Value = varenttype;
dgvDetailsTable.CurrentRow.Cells["txtgradelevel"].Value = GradeLevelValue.Text;
dgvDetailsTable.CurrentRow.Cells["txtFilterType"].Value = FilterFieldValue.Text;
}
}
But I have an issues of where to put it .
I have tried the 2 events above but the result is not satisfactory
Under
private void dgvDetailsTable_CellValueC
The form does not load because it keeps seeing a null reference for the combo which during load is empty.
under
private void dgvDetailsTable_CellDouble
the form loads but getting the mouse double click event to fire has not worked properly.
What i want is that the form form should load first with the List and Combo populated
Then when ever i select a value from the combo the 4 values in the grid should be populated on that particular line.
In other words if i stay on a line and keep changing the combo values the 4 grid values should keep changing.
under which even should i put the script
Thanks
olukay
ASKER
hi Gustav,
Now the form loads with the list AND combo populated with the code below
But nothing happens when the code in the combo is changed
I placed the debugger just before the code and changing the code in the combo
does nothing. The application does not go to that section at all.
Below is the screen shot to show where i have my cursor in the debugger
What am I doing wrong and how can i fix this last bit
I seem so close yet so far !!!!
Thanks
olukay
Now the form loads with the list AND combo populated with the code below
private void dgvDetailsTable_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
string varentcode = "";
string varenttype = "";
var data = (sender as ComboBox).SelectedItem as ProportionsModel;
varentcode = data.Ent_code;
varenttype = data.Ent_type;
dgvDetailsTable.CurrentRow.Cells["txtcmbCode"].Value = varentcode;
dgvDetailsTable.CurrentRow.Cells["txtenttype"].Value = varenttype;
dgvDetailsTable.CurrentRow.Cells["txtgradelevel"].Value = GradeLevelValue.Text;
dgvDetailsTable.CurrentRow.Cells["txtFilterType"].Value = FilterFieldValue.Text;
}
}
But nothing happens when the code in the combo is changed
I placed the debugger just before the code and changing the code in the combo
does nothing. The application does not go to that section at all.
Below is the screen shot to show where i have my cursor in the debugger
What am I doing wrong and how can i fix this last bit
I seem so close yet so far !!!!
Thanks
olukay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did not get it to work.
But i will continue to struggle to fix it.
Thanks
Olukay
But i will continue to struggle to fix it.
Thanks
Olukay
Open in new window