Reputation: 883
I have the following class and I want to get the current selected row value and set it to a textbox:
private void UpdateWines() {
string evalStr = "(WINES::get-wine-list)";
MultifieldValue mv = (MultifieldValue)enviroment.Eval(evalStr);
List<WineRecommendation> wineRecList = new List<WineRecommendation>();
for (int i = 0; i < mv.Count; i++) {
FactAddressValue fv = (FactAddressValue)mv[i];
int certainty = (int)((FloatValue)fv.GetFactSlot("certainty"));
String wineName = ((StringValue)fv.GetFactSlot("value"));
wineRecList.Add(new WineRecommendation() { WineName = wineName, Certainty = certainty });
}
dataGridView.DataSource = wineRecList;
//richTextBox1.Text = dataGridView1.SelectedCells[0].Value;
richTextBox1.Text = dataGridView.CurrentCell.RowIndex.ToString();
}
I used richTextBox1.Text = dataGridView.CurrentCell.RowIndex.ToString();
to get wineName but it returns 0;
Here's an image:
Upvotes: 1
Views: 16110
Reputation: 31
this is work for me:
private void dgvSubject_CellClick(object sender, DataGridViewCellEventArgs e)
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dgvSubject.Rows[e.RowIndex];
txtSubjectCode.Text = row.Cells["isid"].Value.ToString();
}
--jongvelasquez
Upvotes: 2
Reputation: 457
try this
richTextBox1.Text=dataGridView1.Rows[e.RowIndex].Cells["Your Coloumn name"].Value.ToString();
Upvotes: 1