TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed salah
NA
530
148.3k
How to get selected text for combox box in datagridview
Mar 10 2017 11:03 PM
I work in windows form c# vs 2015
i need to get text of selected value of combobox inside datagridview
i can added success in datagridview but cannot get text for it .
I replaced by column already exist his name Country
and become Country2
this code of combobox
Actually i need to get selected text of country to update data gridview
but i cannot do that so that can you help me in that ?
my update based on updated country where userid=userid
so that i need country text of combobox added
private
void
dataGridView1_CellContentClick(
object
sender, DataGridViewCellEventArgs e)
{
if
(e.ColumnIndex >= 0)
{
if
(dataGridView1.Columns[e.ColumnIndex].Name ==
"Save"
)
{
indexRow = e.RowIndex;
// get the selected Row Index
DataGridViewRow row3 = dataGridView1.Rows[indexRow];
//ComboBox cmbBox = e.Control as ComboBox;
//cmbBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
//MessageBox.Show(str);
//dataGridView1.CurrentRow.Cells["Country"].Value.ToString();
// dataGridView1.CurrentRow.Cells[0].Value.ToString();
//QrClasses qrc = new MatrixBarcode.QrClasses();
//string valueupdate = qrc.updatedatagridview(dataGridView1.CurrentRow.Cells[5].Value.ToString(), row3.Cells[2].Value.ToString());
//if (valueupdate != null)
//{
// MessageBox.Show("??? ?? ??????? ?????");
//}
}
if
(dataGridView1.Columns[e.ColumnIndex].Name ==
"Edit"
)
{
dataGridView1.Columns[
"Country"
].Visible =
false
;
DataGridViewComboBoxColumn cmbCol =
new
DataGridViewComboBoxColumn();
cmbCol.HeaderText =
"Country"
;
cmbCol.Name =
"Country2"
;
dataGridView1.Columns.Add(cmbCol);
dataGridView1.Columns[
"Country2"
].DisplayIndex = 3;
foreach
(DataGridViewRow row2
in
dataGridView1.Rows)
{
row2.Cells[
"Country2"
].Value = row2.Cells[
"Country"
].Value;
var dataSourceEn =
new
List<Country>();
dataSourceEn.Add(
new
Country() { Name =
"SelectCountry"
, Value = 0 });
dataSourceEn.Add(
new
Country() { Name =
"Jordon"
, Value = 1 });
dataSourceEn.Add(
new
Country() { Name =
"Emarate "
, Value = 2 });
dataSourceEn.Add(
new
Country() { Name =
"Saudia"
, Value = 3 });
dataSourceEn.Add(
new
Country() { Name =
"Bahreen"
, Value = 4 });
dataSourceEn.Add(
new
Country() { Name =
"Tunisi"
, Value = 5 });
dataSourceEn.Add(
new
Country() { Name =
"Algeri"
, Value = 6 });
dataSourceEn.Add(
new
Country() { Name =
"Saudan"
, Value = 7 });
dataSourceEn.Add(
new
Country() { Name =
"Syria"
, Value = 8 });
dataSourceEn.Add(
new
Country() { Name =
"Eraq"
, Value = 9 });
dataSourceEn.Add(
new
Country() { Name =
"Palestin"
, Value = 10 });
dataSourceEn.Add(
new
Country() { Name =
"Qwit"
, Value = 11 });
dataSourceEn.Add(
new
Country() { Name =
"Libanon"
, Value = 12 });
dataSourceEn.Add(
new
Country() { Name =
"Libya"
, Value = 13 });
dataSourceEn.Add(
new
Country() { Name =
"Egypt"
, Value = 14 });
dataSourceEn.Add(
new
Country() { Name =
"Moroco"
, Value = 15 });
dataSourceEn.Add(
new
Country() { Name =
"Mouritania"
, Value = 16 });
dataSourceEn.Add(
new
Country() { Name =
"Yamen"
, Value = 17 });
cmbCol.DataSource = dataSourceEn;
cmbCol.DisplayMember =
"Name"
;
cmbCol.ValueMember =
"Value"
;
}
Save.Visible =
true
;
}
}
}
Reply
Answers (
2
)
how to store using input with System.Speech ??
can any say how to remove the duplicates in a text file