Click here to Skip to main content
15,898,658 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Combobox problem Pin
Hum Dum13-Jun-10 17:41
Hum Dum13-Jun-10 17:41 
GeneralRe: Combobox problem Pin
Luc Pattyn13-Jun-10 18:05
sitebuilderLuc Pattyn13-Jun-10 18:05 
QuestionDisconnect SSL connection after user has logout Pin
tiffanygct10-Jun-10 22:20
tiffanygct10-Jun-10 22:20 
QuestionHow do I find the BITMAPINFOHEADER of a image Pin
TimSWatson10-Jun-10 21:49
TimSWatson10-Jun-10 21:49 
AnswerRe: How do I find the BITMAPINFOHEADER of a image Pin
Henry Minute11-Jun-10 6:11
Henry Minute11-Jun-10 6:11 
GeneralRe: How do I find the BITMAPINFOHEADER of a image Pin
TimSWatson13-Jun-10 21:51
TimSWatson13-Jun-10 21:51 
GeneralRe: How do I find the BITMAPINFOHEADER of a image Pin
Henry Minute14-Jun-10 1:16
Henry Minute14-Jun-10 1:16 
QuestionRandomize from array Pin
Socheat.Net10-Jun-10 21:00
Socheat.Net10-Jun-10 21:00 
AnswerRe: Randomize from array Pin
OriginalGriff10-Jun-10 21:46
mveOriginalGriff10-Jun-10 21:46 
GeneralRe: Randomize from array Pin
Socheat.Net10-Jun-10 22:13
Socheat.Net10-Jun-10 22:13 
GeneralRe: Randomize from array Pin
Socheat.Net11-Jun-10 1:03
Socheat.Net11-Jun-10 1:03 
GeneralRe: Randomize from array Pin
OriginalGriff11-Jun-10 1:19
mveOriginalGriff11-Jun-10 1:19 
GeneralRe: Randomize from array Pin
OriginalGriff11-Jun-10 1:20
mveOriginalGriff11-Jun-10 1:20 
AnswerRe: Randomize from array Pin
Luc Pattyn11-Jun-10 1:44
sitebuilderLuc Pattyn11-Jun-10 1:44 
GeneralRe: Randomize from array Pin
harold aptroot11-Jun-10 1:53
harold aptroot11-Jun-10 1:53 
GeneralRe: Randomize from array Pin
Luc Pattyn11-Jun-10 2:11
sitebuilderLuc Pattyn11-Jun-10 2:11 

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.