Click here to Skip to main content
15,916,600 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using Invoke to Manipulate the UI Pin
Richard Andrew x6419-Oct-11 0:26
professionalRichard Andrew x6419-Oct-11 0:26 
GeneralRe: Using Invoke to Manipulate the UI Pin
Pete O'Hanlon19-Oct-11 0:36
mvePete O'Hanlon19-Oct-11 0:36 
GeneralRe: Using Invoke to Manipulate the UI Pin
BobJanova19-Oct-11 2:38
BobJanova19-Oct-11 2:38 
GeneralRe: Using Invoke to Manipulate the UI Pin
Dave Kreskowiak19-Oct-11 5:07
mveDave Kreskowiak19-Oct-11 5:07 
AnswerRe: Using Invoke to Manipulate the UI Pin
Luc Pattyn19-Oct-11 1:53
sitebuilderLuc Pattyn19-Oct-11 1:53 
GeneralRe: Using Invoke to Manipulate the UI Pin
Reiss18-Oct-11 22:31
professionalReiss18-Oct-11 22:31 
GeneralRe: Using Invoke to Manipulate the UI Pin
Richard Andrew x6419-Oct-11 0:21
professionalRichard Andrew x6419-Oct-11 0:21 
QuestionValueMember and DisplayMember on DataGridViewComboBoxCell Pin
Dewald18-Oct-11 11:29
Dewald18-Oct-11 11:29 
I'm hoping someone can help because I'm stumped here.

I have a DataGridView that is populated with a SQL query. For simplicity's sake, let's say the SQL query is as follows:
SQL
SELECT Name, Number, Lookup FROM ValuesTable


Now, depending on the value of the 'Lookup' column, the value in the 'Number' column can either be a straight forward value (when Lookup==0) or a reference to a different table (when Lookup==1), in which case I want a ComboBox in the cell which shows the various options in that other table.

In other words, I can't really use DataGridViewComboBoxColumn because not all cells in the column are ComboBoxes, only those for which the Lookup value is 1.

So far, so good. In the DataBindingComplete event handler of the DataGridView I have code similar to the following to put a ComboBox (and populate it) into the 'Number' cell of each row that has a value of 1 in the 'Lookup' cell.
C#
foreach (DataGridViewRow row in myDataGridView.Rows)
{
    if (row.Cells["Lookup"].Value.ToString() != "0")
    {
		DataGridViewComboBoxCell myComboCell = new DataGridViewComboBoxCell();
		using (SqlCommand mySqlCommand = new SqlCommand("SELECT Number, Text FROM LookupTable"))
		{
		    using (SqlDataReader mySqlDataReader = sqlCommand.ExecuteReader())
		    {
		        DataSet ds1 = new DataSet();
		        DataTable dt1 = new DataTable();
		        ds1.Tables.Add(dt1);
		        ds1.Load(mySqlDataReader, LoadOption.PreserveChanges, ds1.Tables[0]);
		        myComboCell.DataSource = ds1.Tables[0];
		        myComboCell.DisplayMember = "Text";
		        myComboCell.ValueMember = "Number";
		    }
		}
		row.Cells["Value"] = newCell;
	}
}


This sort of works, but not quite. All the appropriate cells in the DataGridView has a ComboBox inside them and the options of the ComboBox are those retrieved from the Lookup Table. But when an option is selected in a ComboBox and the focus is moved away from that cell, the actual value displayed in the cell is the number by which the value was looked up.

Also, if the DataGridView is populated (like described above), all the cells with ComboBoxes show the number that is stored in the 'Number' field of ValuesTable, not the 'Text' field of LookupTable like myComboCell.DisplayMember = "Text" dictates.

I'd really appreciate if someone could set me straight here.
AnswerRe: ValueMember and DisplayMember on DataGridViewComboBoxCell Pin
egypogramer1-Jan-12 3:05
egypogramer1-Jan-12 3:05 
QuestionOpen multiple pdfs in one window on web Pin
vanikanc18-Oct-11 11:01
vanikanc18-Oct-11 11:01 
AnswerRe: Open multiple pdfs in one window on web Pin
Dennis E White18-Oct-11 11:49
professionalDennis E White18-Oct-11 11:49 
QuestionTab control with pages that are the same. Pin
__John_18-Oct-11 3:14
__John_18-Oct-11 3:14 
AnswerRe: Tab control with pages that are the same. Pin
PIEBALDconsult18-Oct-11 3:26
mvePIEBALDconsult18-Oct-11 3:26 
GeneralRe: Tab control with pages that are the same. Pin
BobJanova18-Oct-11 5:09
BobJanova18-Oct-11 5:09 
GeneralRe: Tab control with pages that are the same. Pin
PIEBALDconsult18-Oct-11 8:01
mvePIEBALDconsult18-Oct-11 8:01 
GeneralRe: Tab control with pages that are the same. Pin
BobJanova18-Oct-11 22:33
BobJanova18-Oct-11 22:33 
AnswerRe: Tab control with pages that are the same. Pin
Wayne Gaylard18-Oct-11 3:31
professionalWayne Gaylard18-Oct-11 3:31 
GeneralRe: Tab control with pages that are the same. Pin
__John_18-Oct-11 4:18
__John_18-Oct-11 4:18 
AnswerRe: Tab control with pages that are the same. Pin
BillWoodruff19-Oct-11 23:05
professionalBillWoodruff19-Oct-11 23:05 
QuestionWhich IP Address Represents LocalHost Pin
Richard Andrew x6417-Oct-11 20:32
professionalRichard Andrew x6417-Oct-11 20:32 
AnswerRe: Which IP Address Represents LocalHost [SOLVED] Pin
Richard Andrew x6417-Oct-11 20:45
professionalRichard Andrew x6417-Oct-11 20:45 
GeneralRe: Which IP Address Represents LocalHost [SOLVED] Pin
Richard MacCutchan17-Oct-11 23:18
mveRichard MacCutchan17-Oct-11 23:18 
AnswerRe: Which IP Address Represents LocalHost Pin
Abhinav S18-Oct-11 3:29
Abhinav S18-Oct-11 3:29 
GeneralRe: Which IP Address Represents LocalHost Pin
Dave Kreskowiak18-Oct-11 4:10
mveDave Kreskowiak18-Oct-11 4:10 
GeneralRe: Which IP Address Represents LocalHost Pin
jschell18-Oct-11 8:28
jschell18-Oct-11 8:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.