Click here to Skip to main content
15,921,884 members
Home / Discussions / C#
   

C#

 
GeneralRe: Threading Question Pin
LimitedAtonement11-Jun-10 10:31
LimitedAtonement11-Jun-10 10:31 
GeneralRe: Threading Question Pin
Luc Pattyn11-Jun-10 11:23
sitebuilderLuc Pattyn11-Jun-10 11:23 
GeneralRe: Threading Question Pin
Daniel Grunwald11-Jun-10 13:58
Daniel Grunwald11-Jun-10 13:58 
GeneralRe: Threading Question Pin
Luc Pattyn11-Jun-10 14:58
sitebuilderLuc Pattyn11-Jun-10 14:58 
AnswerRe: Threading Question Pin
LimitedAtonement15-Jun-10 2:49
LimitedAtonement15-Jun-10 2:49 
QuestionRe: Threading Question Pin
LimitedAtonement15-Jun-10 2:48
LimitedAtonement15-Jun-10 2:48 
QuestionProblem Here how can i deal [modified] Pin
Pellatrex11-Jun-10 2:14
Pellatrex11-Jun-10 2:14 
AnswerRe: Problem Here how can i deal Pin
Richard MacCutchan11-Jun-10 2:55
mveRichard MacCutchan11-Jun-10 2:55 
AnswerRe: Problem Here how can i deal Pin
R. Giskard Reventlov11-Jun-10 2:55
R. Giskard Reventlov11-Jun-10 2:55 
AnswerRe: Problem Here how can i deal Pin
Peace ON11-Jun-10 2:56
Peace ON11-Jun-10 2:56 
AnswerRe: Problem Here how can i deal Pin
Luc Pattyn11-Jun-10 3:00
sitebuilderLuc Pattyn11-Jun-10 3:00 
AnswerRe: Problem Here how can i deal Pin
harold aptroot11-Jun-10 3:00
harold aptroot11-Jun-10 3:00 
GeneralRe: Problem Here how can i deal Pin
Luc Pattyn11-Jun-10 3:47
sitebuilderLuc Pattyn11-Jun-10 3:47 
AnswerRe: Problem Here how can i deal Pin
riced11-Jun-10 4:29
riced11-Jun-10 4:29 
GeneralRe: Problem Here how can i deal Pin
Eddy Vluggen11-Jun-10 5:10
professionalEddy Vluggen11-Jun-10 5:10 
GeneralRe: Problem Here how can i deal Pin
Luc Pattyn11-Jun-10 5:25
sitebuilderLuc Pattyn11-Jun-10 5:25 
AnswerRe: Problem Here how can i deal Pin
i.j.russell12-Jun-10 0:03
i.j.russell12-Jun-10 0:03 
QuestionCombobox problem Pin
Hum Dum10-Jun-10 23:02
Hum Dum10-Jun-10 23:02 
AnswerRe: Combobox problem Pin
ddecoy11-Jun-10 1:15
ddecoy11-Jun-10 1:15 
GeneralRe: Combobox problem Pin
Hum Dum11-Jun-10 1:58
Hum Dum11-Jun-10 1:58 
AnswerRe: Combobox problem Pin
Luc Pattyn11-Jun-10 1:21
sitebuilderLuc Pattyn11-Jun-10 1:21 
GeneralRe: Combobox problem Pin
ddecoy11-Jun-10 1:41
ddecoy11-Jun-10 1:41 
GeneralRe: Combobox problem Pin
Luc Pattyn11-Jun-10 1:59
sitebuilderLuc Pattyn11-Jun-10 1:59 
GeneralRe: Combobox problem Pin
Hum Dum11-Jun-10 2:27
Hum Dum11-Jun-10 2:27 
When i use SelectedText, its give previously name.
But if i use SelectedIndex, its giving currently selected item.

I am trying to achieve. There is a DataGridView. I am filling DataSet with approx 20 tables. Then adding these Datatable names to combobox.

Now when user selects a Datatable from comboxbox, lsetting dataMember property of DataGridView to Table Name.

Ques -> Is this Approach correct?
Here i also have to declare DataSet at class level (which i think remain in memory until class/application alive).
void SomeMethod()
{
      dsTemp = new DataSet();
      dsTemp.ReadXml(ofdXmlFile.FileName);
      dgvDS.DataSource = dsTemp;

      for (int i = 0; i < dsTemp.Tables.Count; i++)
      {
           txtContent.Text += dsTemp.Tables[i].TableName + "\r\n";
           cmbTables.Items.Add(dsTemp.Tables[i].TableName);
      }
}

DataSet dsTemp = null;
        
private void cmbTables_SelectedIndexChanged(object sender, EventArgs e)        
{
      dgvDS.Columns.Clear();
      dgvDS.DataMember = dsTemp.Tables[cmbTables.SelectedIndex].TableName;
}



Now above working correctly.

But when i use this below one its not working as expected
But here i dont have to declare DataSet at class level(and it also got garbage collected once SomeMethod Exit).
void SomeMethod()
{
       DataSet dsTemp = new DataSet();
       dsTemp.ReadXml(ofdXmlFile.FileName);
       dgvDS.DataSource = dsTemp;

       for (int i = 0; i < dsTemp.Tables.Count; i++)
       {
            txtContent.Text += dsTemp.Tables[i].TableName + "\r\n";
            cmbTables.Items.Add(dsTemp.Tables[i].TableName);
       }
}
        
private void cmbTables_SelectedIndexChanged(object sender, EventArgs e)
{
       dgvDS.Columns.Clear();
       dgvDS.DataMember = cmbTables.SelectedText;
}



Also one more quest, when i try to iterate dataset thru foreach loop like
foreach (DataTable dt in dsTemp)
{     txtContent.Text += dt.TableName + "\r\n";
      cmbTables.Items.Add(dsTemp.Tables[i].TableName);
}
it gives error why?

Error 1 foreach statement cannot operate on variables of type 'System.Data.DataSet' because 'System.Data.DataSet' does not contain a public definition for 'GetEnumerator'


How to overcome this? if i want to use foreach only?
GeneralRe: Combobox problem [modified] Pin
Luc Pattyn11-Jun-10 2:45
sitebuilderLuc Pattyn11-Jun-10 2:45 

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.